英文:
fgetc is giving me incorrect character
问题
I wrote a program that opens a diff file and is supposed to parse through the output. However, I can't even get to the parsing part of the algorithm. I decided to open the diff file in my main to troubleshoot what my first character in the stream is, and it doesn't match what is in the file. The first character in the file is '1', but when I run the code below, I get 49. I have no idea what has gone wrong. Can anyone guide me? Thank you in advance.
FILE *diff = fopen(diff_filename, "r");
int what;
what = fgetc(diff);
fprintf(stderr, "%d\n", what);
I tried to cast the output to a char variable, it still remains 49.
英文:
I wrote a program that opens a diff file and is supposed to parse through the output. However, I can't even get to the parsing part of the algorithm. I decided to open the diff file in my main to troubleshoot what my first character in the stream is, and it doesn't match what is in the file. The first character in the file is '1', but when I run the code below, I get 49. I have no idea what has gone wrong. Can anyone guide me? Thank you in advance.
FILE *diff = fopen(diff_filename,"r");
int what;
what = fgetc(diff);
fprintf (stderr,"%d\n",what);
I tried to cast the output to a char variable, it still remains 49.
答案1
得分: 1
你的 fpritnf()
格式字符串是错误的。如果你想要一个字符表示,应该是:
fprintf (stderr,"%c\n",what);
英文:
Your fpritnf()
format string is wrong. If you want a character representation it should be:
fprintf (stderr,"%c\n",what);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论