第2个回答 推荐于2016-01-09
#include<stdio.h>
#include<stdlib.h>
void main ()
{
char s1[80],s2[80];
int a1,a2;
FILE *fp;
if((fp=fopen("t.txt","r"))==NULL)
{
printf("open wrong");
exit(1);
}
fscanf(fp,"%s%s%d%d",s2,s1,&a1,&a2);
fprintf(stdout,"%s,%s,%d,%d\n",s1,s2,a1,a2);
}
把ABC DEF 10 20存在t.txt中
读取并保存在 s1,s2,a1,a2
输出本回答被提问者采纳
第4个回答 2010-04-23
用fscanf()就可以啦,
char a[80],b[80];
int c,d;
FILE *fp=fopen("data.txt","r");
fscanf(fp,"%s %s %d %d",a,b,&c,&d);