dimanche 1 mars 2015

fgetc returns a strange character



I am reading input until EOF with fgetc(). I am running into a strange problem. Right before EOF, I am getting a char \337. I am not sure what that is.


Here is my code implementation:



char *get_file_paths()
{
char *return_str = NULL;
int chars_read = 0;
size_t buf_sz = 80;

return_str = (char *) malloc(buf_sz * sizeof(char));

while((*(return_str + chars_read) = fgetc(stdin)) != EOF) {
chars_read++;
if ((chars_read + 1) == buf_sz) {
buf_sz *= 2;
return_str = realloc(return_str, buf_sz);
}
}

return return_str;

}


For instance, if I had a string :assignment_2/grepout.txt. I am getting the following when viewing return_str in gdb:



assignment_2/grepout.txt\n\337


I am really curious what that means. I looked online, but there is no mention of it. Could it be platform specific?


I am running the following version of gcc:



gcc version 4.8.1 20130909 [gcc-4_8-branch revision 202388] (SUSE Linux)


And I am running openSuse.




Aucun commentaire:

Enregistrer un commentaire