Can someone explain this method to me and why is this returning char
instead of int
??
public static int fgetc(InputStream stream)
{
char ToRet = '\0';
if (InStream.isEmpty())
{
try
{
ToRet = (char) stream.read();
if (ToRet == CR)
Toret = (char) stream.read();
if ((int) ToRet == 0xFFFF)
return EOF;
}
catch (EOFException eof)
{
return EOF;
}
catch (IOException ioe)
{
writeline ("Unexpected IO Exception caught!\n", System.out);
writeline (ioe.toString(),System.out);
}
}
else
ToRet = ((MYLibCharacter) Instream.pop ()).charValue();
return ToRet;
}
and lets say you want to store the value that the user input as a character until the newline is detected,
int index = 0;
while (message[index] != '\n\)
{
message[index] = fgetc(System.in);
index++;
}
why is this wrong?? Any tips and help would be much appreciated.
sorry this might be a little messy, feel free to edit or ask me any questions regarding this post.