在C语言I/O中如何将文件的一行字符串转化为字符串数组???
在C语言I/O中如何将文件的一行字符串转化为字符串数组???
[解决办法]
定义一个char数组,然后fopen打开文件,再fread读取到数组中
[解决办法]
//文件中是:
// 学号 姓名 性别 成绩
// 如何变成
// {"学号","姓名","性别","成绩"};
#include <stdio.h>
char s[4][5];
FILE *f;
int main() {
f=fopen("in.txt","r");
if (NULL==f) {
printf("Can not open file in.txt!\n");
return 1;
}
fscanf(f,"%4s%4s%4s%4s",s[0],s[1],s[2],s[3]);
fclose(f);
printf("%s %s %s %s\n",s[0],s[1],s[2],s[3]);
return 0;
}