1 //fprintf函数将数据按指定格式写入指定文件中,与printf函数相似 2 //形式为 fprintf(文件指针,格式字符串,输出列表) 3 #include<stdio.h> 4 #include<stdlib.h> 5 int main(){ 6 FILE *fp; 7 int i=10,j=12; 8 double m=1.5,n=2.345; 9 char s[]="This is a string"; 10 char c='\n'; 11 if( (fp=fopen("file_data.txt","w"))==NULL ){ 12 printf("打开文件失败\n"); 13 exit(0); 14 } 15 fprintf(fp,"%s%c",s,c); 16 fprintf(fp,"%d %d\n",i,j); 17 fprintf(fp,"%lf %lf\n",m,n); 18 fclose(fp); 19 return 0; 20 }
C语言学习(36)
猜你喜欢
转载自www.cnblogs.com/Tobi/p/9239795.html
今日推荐
周排行