失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 使用fprintf()函数格式化输出至磁盘文件和是stdout

使用fprintf()函数格式化输出至磁盘文件和是stdout

时间:2021-06-13 20:41:47

相关推荐

使用fprintf()函数格式化输出至磁盘文件和是stdout

独角兽企业重金招聘Python工程师标准>>>

//numberfile.c--演示fprintf()函数的用法#include<stdio.h>#include<stdlib.h>voidclear_kb(void);intmain(void){FILE*fp;floatdata[5];intcount;charfilename[20];puts("Enter5floating-pointnumericalvalues:");for(count=0;count<5;count++)scanf("%f",&data[count]);//获得文件名,并打开文件。首先要清除stdin中的额外字符clear_kb();puts("Enteranameforthefile:");gets(filename);if((fp=fopen(filename,"w"))==NULL){fprintf(stderr,"Erroropeningfile%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");return0;}//清理stdin中的其他字符voidclear_kb(void){charjunk[80];gets(junk);}

如果觉得《使用fprintf()函数格式化输出至磁盘文件和是stdout》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。