标签:fopen pause char s ima 命令 黄色 字符 信息 文件中
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main() {
FILE * fp;
int i;
char name_classmates[10][20] = { "张旭","陈烜","朱仕岳","茅志雄","李龙生","吴执涛","洪礼强","李欣欣","笨笨","宋思坡" };
for (i = 0; i < 10; i++) {
strcat(name_classmates[i], ".txt");
if ((fp = fopen(name_classmates[i], "w"))==NULL) {
printf("File open error!\n");
exit(0);
}
if (fclose(fp)) {
printf("Can not close the file\n");
exit(0);
}
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct astudent {
char name[10];
char Number_stu[25];
char sex[10];
char Class[10];
char score[5];
};
int main() {
FILE * fp;
int i;
struct astudent students[10];
char name_classmates[10][20] = { "张旭","陈烜","朱仕岳","茅志雄","李龙生","吴执涛","洪礼强","李欣欣","笨笨","宋思坡" };
printf("请依次输入学号,性别,班级,线代成绩\n");
printf("姓名: 学号: 性别: 班级: 线代成绩: \n");
for (i = 0; i < 10; i++) {
printf("%s",name_classmates[i]);//在每行开头输出该同学的姓名,随后依次读入学号、性别、班级、线代成绩
strcat(name_classmates[i], ".txt");
if ((fp = fopen(name_classmates[i], "w"))==NULL) {
printf("File open error!\n");
exit(0);
}
scanf("%s %s %s %s", students[i].Number_stu, students[i].sex, students[i].Class, students[i].score);
fprintf(fp, "%s %s %s %s", students[i].Number_stu, students[i].sex, students[i].Class, students[i].score);
if (fclose(fp)) {
printf("Can not close the file\n");
exit(0);
}
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct astudent {
char name[10];
char Number_stu[25];
char sex[10];
char Class[10];
char score[5];
};
int main() {
FILE * fp;
int i;
struct astudent students[10];
char name_classmates[10][20] = { "张旭","陈烜","朱仕岳","茅志雄","李龙生","吴执涛","洪礼强","李欣欣","笨笨","宋思坡" };
for (i = 0; i < 10; i++) {
strcpy(students[i].name, name_classmates[i]);
strcat(name_classmates[i], ".txt");
if ((fp = fopen(name_classmates[i], "r"))==NULL) {
printf("File open error!\n");
exit(0);
}
fscanf(fp, "%s %s %s %s", students[i].Number_stu, students[i].sex, students[i].Class, students[i].score);
if (fclose(fp)) {
printf("Can not close the file\n");
exit(0);
}
}
printf("姓名: 学号: 性别: 班级: 线代成绩: \n");
for (i = 0; i < 10; i++) {
printf("%-11s%-13s%-11s%-11s%s\n", students[i].name, students[i].Number_stu, students[i].sex, students[i].Class, students[i].score);
}
return 0;
}
system("pause") //暂停,按任意键继续
system("cls") //清屏
system("color 0A"); 其中color后面的0是背景色代号,A是前景色代号。
0=黑色 1=蓝色 2=绿色 3=湖蓝色 4=红色 5=紫色 6=黄色 7=白色 8=灰色 9=淡蓝色 A=淡绿色 B=淡浅绿色 C=淡红色 D=淡紫色 E=淡黄色 F=亮白色
1.对文件的操作如fscanf、fprintf、fopen,fclose更加熟练。
2.学习了system("pause")和system("cls")命令,百度了一个改变运行框颜色的system语句——system("color 0A")。
3.本次作业主要练习关于文本文件的基本操作,没用到二进制文件的操作。
标签:fopen pause char s ima 命令 黄色 字符 信息 文件中
原文地址:https://www.cnblogs.com/cjt0722/p/12064123.html