fgetc 返回了不正确的字符

huangapple go评论60阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2023年2月19日 09:23:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497442.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定