使用fprintf()函数格式化输出至磁盘文件和是stdout
生活随笔
收集整理的這篇文章主要介紹了
使用fprintf()函数格式化输出至磁盘文件和是stdout
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
//numberfile.c?--?演示fprintf()函數的用法 #include?<stdio.h> #include?<stdlib.h>void?clear_kb(void);int?main(void){FILE?*fp;float?data[5];int?count;char?filename[20];puts("Enter?5?floating-point?numerical?values:");for(count?=?0;?count?<?5;?count++)scanf("%f",?&data[count]);//?獲得文件名,并打開文件。首先要清除stdin中的額外字符clear_kb();puts("Enter?a?name?for?the?file:");?gets(filename);if((fp?=?fopen(filename,?"w"))?==?NULL){fprintf(stderr,?"Error?opening?file?%s.",?filename);exit(1);}for(count?=?0;?count?<?5;?count++){//將數值輸出到磁盤文件?fprintf(fp,?"\ndata[%d]?=?%f",?count,?data[count]);//將數值輸出到流?fprintf(stdout,?"\ndata[%d]?=?%f",?count,?data[count]);}fclose(fp);printf("\n");return?0; } //?清理stdin中的其他字符? void?clear_kb(void){char?junk[80];gets(junk); }轉載于:https://my.oschina.net/u/241930/blog/519098
總結
以上是生活随笔為你收集整理的使用fprintf()函数格式化输出至磁盘文件和是stdout的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 实现事件来回切换
- 下一篇: Gallery简单应用