第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這幾行代碼為什么不能運行出來?

這幾行代碼為什么不能運行出來?

C
sunny超1 2017-10-21 17:19:49
#include<stdio.h>#define SIZE 5struct student{?long num;?char name[10];?int score[3];}stu[SIZE];void save(){?FILE *fp; int i;?if((fp=fopen("C:\\stud.txt","w"))==NULL)?{??printf("cannot open file\n");??return;}?for(i=0;i<SIZE;i++)??if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1)???printf("file write error\n");??fclose(fp);}main(){?int i;?for(i=0;i<SIZE;i++)???scanf("%ld%s%d%d%d",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);??save();}
查看完整描述

2 回答

?
噗_嗤

TA貢獻1條經(jīng)驗 獲得超0個贊

不知道題主用的是什么,我這邊用VS和VC都能跑,只是有個warn,這在main()之前加個int就可以解決。我猜測是路徑問題,修改一下這一句。

?if((fp=fopen("C:\\stud.txt","w"))==NULL)

? ? ? ? ? ? ? ? ? ? ?

查看完整回答
反對 回復(fù) 2017-10-22
  • sunny超1
    sunny超1
    感謝你的回答,冒昧問您一句,是不是換成類似于這樣 if((fp=fopen("D:\\stud.txt","w"))==NULL)這種?還有就是這幾行運行完后出來得命令提示符,輸入其中的數(shù)據(jù),生成的名為stud的TXT文件是亂碼的,又是哪里有問題呢?期待你的再次回復(fù)。
  • 噗_嗤
    噗_嗤
    可能我沒有寫清楚,我的意思是這個路徑下有你建立的那個stud.txt文件就行。 還有那個亂碼是因為字幕編碼問題。 fwrite()這個函數(shù)是以二進制寫入的,如果你使用fread()再讀出來其實不是亂碼,而文本只能顯示一部分,所以看起來是亂碼。 如果把fwrite()改成fprintf()就可以,比如改成 fprintf(fp,"%ld%s%d%d%d\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2]);
  • sunny超1
    sunny超1
    恩恩,我立即按照你的方法試了下,可有一個error和一個warning。 #include<stdio.h> #define SIZE 5 struct student{ long num; char name[10]; int score[3]; }stu[SIZE]; void save(){ FILE *fp; int i; if((fp=fopen("C:\\stud.txt","w"))==NULL) { printf("cannot open file\n"); return; } for(i=0;i<SIZE;i++) if(fwrite(&stu[i],sizeof(struct student),1,fp)!=1) printf("file write error\n"); fclose(fp); } int main(){ int i; for(i=0;i<SIZE;i++) fprintf(fp,"%ld%s%d%d%d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]); save(); }
點擊展開后面1
  • 2 回答
  • 0 關(guān)注
  • 1249 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號