此功能应从文本文件中读取第一行并返回。
char *meno(FILE *fin) {
char meno1[50];
fscanf(fin," %[^\n]",meno1 );
return meno1;
}
如果目录中有一个文本文件,则主要功能将其打开并执行上面的功能,并应打印它的返回值(在我的情况下为四个名称),但它不起作用并打印4次“ 8J8”。 / p>
int main() {
FILE *fin;
char s[10], *x=NULL;
int i = 1;
while (1) {
sprintf(s, "text%d.txt", i);
i++;
fin = fopen(s, "r");
if (fin == NULL) {
break;
}
*meno(fin);
printf("%s \n", meno ); // this doesn't work
}
}
我是初学者。