[求助]想用fprintf把内容保存在TXT文件里?
void print(struct student *head){struct student *p;
p=head;
if(head!=null)
do
{printf("%ld% 5.2f\n",p->num,p->score);
p=p->next;
}while(p!=null);
}
想把输出屏幕的那些内容输出到一个“student.txt”文件由于没学过fprintf()函数希望大家帮帮忙拉 :)
void print(struct student *head)
{ FILE *fp;
struct student *p;
if((fp=fopen("student.txt,"a+"))==NULL)
{
puts("不能打开此文件");
exit(0);
}
p=head;
if(head!=null)
do
{fprintf(fp,"%ld% 5.2f\n",p->num,p->score);
p=p->next;
}while(p!=null);
}
应该是这样