📅  最后修改于: 2020-09-25 08:40:19             🧑  作者: Mango
vfscanf() 函数在
int vfscanf(FILE* stream, const char* format, va_list vlist );
所述vfscanf() 函数从该文件读取流的数据stream
通过所定义和存储的值到相应位置vlist
。
#include
#include
void read(FILE* fp, const char * format, ... )
{
va_list args;
va_start (args, format);
vfscanf (fp, format, args);
va_end (args);
}
int main ()
{
char myFriends[5][20] = {"Robert", "Syd", "Brian", "Eddie", "Ray"};
FILE *fp = fopen("example.txt","w+");
char name[20];
for (int i=0; i<5; i++)
fprintf(fp, "%s ", myFriends[i]);
rewind(fp);
printf("Here are the list of my friends\n");
for (int i=0; i<5; i++)
{
read(fp, "%s ", &name);
printf("%s\n", name);
}
fclose(fp);
return 0;
}
运行该程序时,可能的输出为:
Here are the list of my friends
Robert
Syd
Brian
Eddie
Ray