【发布时间】:2023-04-07 11:52:01
【问题描述】:
我不明白stdin和fscanf之间的联系
struct musteri{
int no;
char name[40];
char surname[25];
double arrear;
};
int main() {
struct musteri hesapBilgi={0,"","",0.0};
FILE *ptr;
if((ptr=fopen("eleman.txt","r+"))==NULL){
printf("error");
}
else{
printf("\n enter a no if you want exit enter 0 -->");
scanf("%d",&hesapBilgi.no);
scanf 接受输入并将 no 放入 sturct musteri
while(hesapBilgi.hesapno !=0){
printf("enter a surname name and arrear --->");
fscanf(stdin,"%s%s%lf",hesapBilgi.surname,hesapBilgi.name,&hesapBilgi.arrear);
fscanf 在这里读取文件中的数据吗?还是发生了其他事情?
fseek(ptr,(hesapBilgi.no-1)*,sizeof(struct musteri),SEEK_SET);
fseek 在做什么?
fwrite(&hesapBilgi,sizeof(struct musteri),1,ptr);
printf("enter a no :");
scanf("%d",&hesapBilgi.no);
}
fclose(ptr);
}
return 0;
}
【问题讨论】:
-
这个问题似乎是两个(不相关的?)问题。
标签: c file stdin scanf randomaccessfile