c语言如何用文件写入数据?求解
void charge (struct Student *pt)
{
int num;
system("cls");
printf("请输入充值金额");
scanf("%d",&num);
pt=(struct Student *)malloc(sizeof(struct Student));
pt->moneyleft=95;
pt->moneyleft+=num;
printf("当前余额%d ",pt->moneyleft);
}
你的写入数据是从文件输入还是输出到文件?
若是输入
FILE *fp=fopen("你的文件名","r");
然后改你的
scanf("%d",&num);
为
fscanf(fp,"%d",&num);
就可以了
如果是输出
FILE *fp=fopen("你的文件名","w");
然后改你的
printf("当前余额%d ",pt->moneyleft);
为
printf(fp,"当前余额%d ",pt->moneyleft);
你都会用结构指针了,文件操作应该了解了
热门标签: