Problem for reading a file

17 Aug 2012

Hello there,

I'm quite a beginner in computing in C and I have trouble to read properly a file using the mbed. I've used the software CodeBlocks to test my programme and it is working perfectly but when I paste my code into the mbed compiler I get some troubles.

Here is my code:

/media/uploads/UniLeedsElec06/code.txt

When compiling, I get a warning : "pointless comparison of unsigned integer with a negative constant". This warning is for the line with: "} while (get_character != EOF);". I think there is probably minor differences between the two compiler I've used and I hope it will be easy to fix it.

Here is the file .txt I have to read.

/media/uploads/UniLeedsElec06/userfile.txt

Thanks for your help !

24 Aug 2012

Warnings do not stop compilation. To get rid of the warning make get_character explicitly signed (EOF is a negative number). Change the line 'char get_character;' to 'signed char get_character;'.

Despite the warning I think that the program should still work. Variable declarations normally default to signed if no modifier is specified.

Hope that helps.

Luth

27 Aug 2012

I finally used another technique by testing a variable which is set to 1 when the end of file is reached and it is working properly.

Thanks a lot for your reply ! I may use it in the future :)

Raphael