java - Possible lossy from int to char; Occurs when reading in from a text file -


i trying implement shunting algorithm, after read in character, need determine if operand or operator. input file has multiple lines of infix expressions convert postfix expressions , evaluate. need read each character of each line, evaluate, , proceed next line. error is:

"error: incompatible types: possible lossy conversion int char"

so here portion of have far:

 bufferedreader input = new bufferedreader(new filereader("input.txt"));          char token;         char popop;         int popint1;         int popint2;         int result;         string line;         char temp = 'a';          // while input file still has line characters         while ((line = input.readline()) != null)         {             // create operator , operand stack                                      operatorstack opstack = new operatorstack();             opstack.push(';');             operandstack intstack = new operandstack();              token = input.read(); // first token              if(character.isdigit(token))             {                 system.out.print(token);                 intstack.push(token);             }             else if(token == ')')             {........ 

any appreciated.

there couple issues code:

  1. bufferedreader.read() returns -1 if you've reached end of stream. you're not handling this.
  2. you reading text line line when call input.read() reads first char of next line! either use line.charat(0) or use input.read().

this might fix problem:

   // while there characters consume.     for(int ch; (ch = input.read()) != -1;)     {         // create operator , operand stack                                  operatorstack opstack = new operatorstack();         opstack.push(';');         operandstack intstack = new operandstack();          token = (char)ch; // token          if(token == '\r' || token == '\n')  // handling line ends.              continue;          if(character.isdigit(token))         {             system.out.print(token);             intstack.push(token);         }         else if(token == ')')         {........ 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -