C言語なら俺に聞け! Part 98
■ このスレッドは過去ログ倉庫に格納されています
0503超初心者
NGNG1文字をカウントしたいのですが、0文字になってしまいます。
どこに問題があるのでしょうか?
#include <stdio.h>
#include <fcntl.h>
int main(void)
{
int fd;
int n_read;
int count = 0;
int ch;
char buf[256];
fd = open("data.dat", O_RDONLY, 0);
fprintf(stdout, "Input a letter you want to count.\n");
ch = fgetc(stdin);
while ((n_read = read(fd, buf, 1)) > 0) {
if (buf == ch)
count++;
}
fprintf(stdout, "found %d%c.\n", count, ch);
close(fd);
return 0;
}
■ このスレッドは過去ログ倉庫に格納されています