typedef struct student
{
int zh;
char pw[20];
} STU;
int main()
{
fp = fopen("aaa.txt","w+");
printf("请依次输入相关信息,用空格隔开\n");
scanf("%d %s",&pStu->zh,pStu->pw);
printf("&注册完成&!");
fwrite(pStu,sizeof(STU),1,fp);
fclose(fp);
return 0;
}
C语言里面用“w”打开的文件只能向该文件写入。若打开的文件不存在,则以指定的文件名建立该文件,若打开的文件已经存在,则将该文件删去,重建一个新文件。若要向一个已存在的文件追加新的信息,只能用“a”方式打开文件。但此时该文件必须是存在的,否则将会出错。
楼上正解,file mode use a
a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file.