赞
踩
1.格式化读写文件函数
函数的调用:
fprintf(文件指针,格式字符串,输出表列);
fscanf(文件指针,格式字符串,输出表列);
函数功能:
从磁盘文件中读入或输出字符串
fprintf和printf函数相似:
printf是将数据输出到屏幕上(标准输出)
fprintf函数是将数据输出到文件指针所指定的文件中
printf("%d %s %f %c\n",r_msg[i].id,r_msg[i].name,r_msg[i].score,r_msg[i].sex);
fscanf和scanf函数相似:
scanf是从键盘上(标准输入)获取输入
fscanf函数是从文件指针所标示的文件中获取输入。
fscanf(fp,"%d %s %f %c\n",&r_msg[i].id,r_msg[i].name,&r_msg[i].score,&r_msg[i].sex);
- #include<stdio.h>
-
- typedef struct stu
- {
- int id;
- char name[20];
- float score;
- char sex;
- }MSG;
-
- int main()
- {
- MSG msg[4] = {
- {1001,"李磊",98,'m'},
- {1002,"韩梅梅",77,
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。