C语言的sprintf函数问题,到底怎么用啊??? 5
txt文件里的数字都显示为乱码,我想用sprintf函数把数字转为字符串,在txt文件里才能显示出来吧,可是sprintf(char*buffer,constchar*f...
txt文件里的数字都显示为乱码,我想用sprintf函数把数字转为字符串,在txt文件里才能显示出来吧,可是sprintf( char *buffer, const char *format, [ argument] … );里的char*buffer这里应该怎么搞?我的不对,能帮我改一下吗?多谢!!源代码:#include<stdlib.h>#include<stdio.h>typedef struct{ long unsigned id; char name[20]; double grades;}student;int main(){ char ch,num[80]; student s; char*c; FILE*fp; fp=fopen("lalala.txt","wb"); if(!fp) { printf("file cannot be opened"); exit(1); } printf("input records:\n"); while(1) { printf("id: "); gets(num); s.id=atol(num); sprintf(c,"%s",s.id); printf("name: "); gets(s.name); printf("grades:"); gets(num); s.grades=atof(num); fwrite(&s,sizeof(s),1,fp); printf("another(y/n)?\n"); ch=getchar(); if(ch=='n') break; gets(num); } fclose(fp); return 0;}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询