11 years, 3 months ago.

Problems with file reading

Hello

I have a problem. I want to read a few lines from a file and attached to a string and then sent to the PC. However, it does not work. He comes in the loop, but the mbed doesn't go back out of the while loop. I tried it with getc and fgetc, in both comes a warning. What can I do?

"pointless comparison of unsigned integer with a negative constant" in file "/main.cpp", Line: 35, Col: 40

Code

while((uebertragenBytes = fgetc(fp)) != EOF) {
   Bytes += uebertragenBytes;
    }
    myled1 = 1;
    
    pc.printf("%s", Bytes);

1 Answer

11 years, 3 months ago.

Is uebertragenBytes a signed int? Otherwise it can get into an infinite loop, see: http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1048865140&id=1043284351.

Accepted Answer

Declaration:

char uebertragenBytes; string Bytes;

That's it. Not specially signed or something.

posted by Franziska Gerlich 31 Jul 2013

Ohh wait. Thank you.

I've change char to int and then it works :)

posted by Franziska Gerlich 31 Jul 2013