C語言之檔案操作06——寫資料到文字檔遇0停止

來源:互聯網
上載者:User

標籤:post   檔案   oid   題目   null   void   失敗   pre   儲存   

//檔案
/*
===============================================================
題目:輸入10個籃球運動員的身高資料(cm)儲存至D盤檔案high.txt:
0表示輸入完成。
x= 180 182 179 185 191 178 184 185 183 192
===============================================================
*/
#include<stdio.h>
void main()
{
FILE *fp;
int x;
fp=fopen("D:\\high.txt","w");
if(fp==NULL)
printf("檔案開啟失敗!\n");
else
{
while(x!=0)
{
scanf("%d",&x);
fprintf(fp,"%4d ",x);
}
fclose(fp);
}
}

/*
========================================================================
評:
fprintf(fp,"%d",x);而fscanf時有&,如(fp,"%d",&x);
數組的輸入問題,僅僅是控制語句不同。


========================================================================

*/




C語言之檔案操作06——寫資料到文字檔遇0停止

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.