.定义一个结构体,包含:姓名,学号,性别,C语言成绩;从键盘分布输入这些信息,要求:等所有信息输入
求解用c做 展开
测试:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct __student_informations{
char name[32];
char serial[32];
char sex[16];
char score[64];
}ST_INFO;
int main(int argc, char *argv[])
{
ST_INFO student;
FILE* f;
char name[32];
char serial[32];
char sex[16];
char score[64];
memset(student.name, 0, 32);
memset(student.serial, 0, 32);
memset(student.sex, 0, 16);
memset(student.score, 0, 64);
strcat(student.name, "\n姓名:");
strcat(student.serial, "\n学号:");
strcat(student.sex, "\n性别:");
strcat(student.score, "\nC语言成绩:");
printf("输入姓名:");
scanf("%s", name);
printf("输入学号:");
scanf("%s", serial);
printf("输入性别:");
scanf("%s", sex);
printf("输入C语言成绩:");
scanf("%s", score);
printf("输入完毕, 保存学生信息到文件Student.txt中。\n");
strcat(student.name, name);
strcat(student.serial, serial);
strcat(student.sex, sex);
strcat(student.score, score);
f = fopen("Student.txt", "w");
fwrite(&student, sizeof(student), 1, f);
fclose(f);
return 0;
}