Fscanf不起作用,我不明白为什么。它只读取字符串,而不读取其他内容。1 2 3写入file.txt。这是代码:
include<stdio.h>
int main()
{
FILE* ptr = fopen("file.txt","r");
if (ptr==NULL)
{
printf("no such file.");
return 0;
}
char* buf[100];
int a;
fscanf(ptr," %d ",a);
printf("%d\n", a);
fscanf(ptr," %s ",buf);
printf("%s\n", buf);
return 0;
}
fscanf()
的可变参数必须是指针。