Rumah  >  Soal Jawab  >  teks badan

请教C语言字符串和字符数组的比较问题

用C语言读取1.txt文本文件:
文件内容如下:
12345
67890
98741

程序如下:

include <stdio.h>

include <string.h>

include <stdlib.h>

int main(void)
{
FILE *fp = fopen("1.txt","r");
char *s="12345"; 
char buff[500]; 
while(fgets(buff,499,fp) != NULL)

if(strcmp(buff,s)==0) //为什么这里与“12345”比较没有等于0的时候呢
printf("%s",buff);

}
fclose(fp);
system("pause");
return 0;
}
//结果没有输出,应该怎么使用strcmp函数呢?


高洛峰高洛峰2889 hari yang lalu698

membalas semua(1)saya akan balas

  • 三叔

    三叔2016-10-25 13:26:40

    你的1.txt是用什么编码保存的?

    balas
    0
  • Batalbalas