如何用fscanf实现从txt文件读入多个字符串,读到结尾结束?
热心网友
#include int main(int argc, char * argv[]){ FILE * fp; int count; char buf[1024+1]; fp = fopen(argv[1], "r"); while (1) { memset(buf, 0, sizeof(buf)); count = fscanf(fp, "%s", buf); if (count != 1) break; printf("buf = %s\n", buf); } fclose(fp); return (0);}注意:1)没有做错误处理2)字符串不能超过1024字节长