📄 students_change.c
字号:
/*******************************************************************************/
/* A Simple Student Information System */
/* Copyright From QiJin */
/*******************************************************************************/
#include<stdio.h>
#include<stdlib.h>
/********************************************************************************/
#define MAX 100
struct stu_imfo{
char name[14]; /*Student's Name*/
char sex[8]; /*Student's Sex */
char bir[12]; /*Student's Birthday*/
}student[MAX];
void init_list(void);
void enter(void);
void display(void);
void load(void);
void save(void);
int menu(void);
int isfree(void);
/**********************************************************************************/
int main(void)
{
char choice;
init_list(); /*Sub Function of Initial The Student Information Array */
for(;;)
{
choice = menu();
switch(choice)
{
case 1: enter();
break;
case 2: display();
break;
case 3: save();
break;
case 4: load();
break;
case 5: exit(0);
}
}
return 0;
}
/********************************************************************************/
/* Sub Function of Initial The Student Information Array*/
void init_list(void)
{
int t;
for(t=0;t<MAX;++t)
student[t].name[0] = '\0';
}
/*********************************************************************************/
/* Sub Function of Main Menu :) */
int menu(void)
{
char s[80];
int c;
printf("********************************************\n");
printf("*** Copyright from QiJin ***\n");
printf("********************************************\n");
printf("********************************************\n");
printf("****** Student Information System ******\n");
printf("******1. Enter a student's information******\n");
printf("******2. Display student's information******\n");
printf("******3. Save all the information ******\n");
printf("******4. Load the file ******\n");
printf("******5. EXIT ******\n");
printf("********************************************\n");
do
{
printf("\n Please enter your choice: ");
gets(s);
c = atoi(s);
}while(c<0 || c>6);
return c;
}
/*********************************************************************************/
/*Sub Function of Input the Student's detail Information */
void enter(void)
{
int free;
free = isfree();
if(free == -1)
{
printf("\n Sorry!The RAM is FULL!");
return;
}
/*Get the Information which The User Input*/
printf("Please enter the Name: ");
gets(student[free].name);
printf("Please enter the Sex: ");
gets(student[free].sex);
printf("Please enter the Birthday: ");
gets(student[free].bir);
}
/**********************************************************************************/
/*Sub Function of Search The free Student Information Array */
int isfree(void)
{
int t;
for(t=0;student[t].name[0] && t<MAX;++t);
if(t==MAX)
return -1; /*Never Find and then return -1*/
return t;
}
/***********************************************************************************/
/*Sub Function of Display The Student's Information */
void display(void)
{
int t;
printf("<==Attention Please!You must save all the information before you exit!==>\n");
printf("<==All the student's information in the RAM is: ==>\n");
for(t=0;t<MAX;++t)
{
if(student[t].name[0])
{
printf("<==The name is:%s ==>\n",student[t].name);
printf("<==The sex is:%s ==>\n",student[t].sex);
printf("<==Birthday is:%s ==>\n\n",student[t].bir);
}
}
printf("\n\n");
}
/******************************************************************************************/
/*Sub Function of Save The Student's Information*/
/*Attention Please!This operation will recover the File!*/
void save(void)
{
FILE *fp;
int i;
if((fp=fopen("stu_imfo","wb")) == NULL)
{
printf("Sorry!Can not open the file!!! \n");
return;
}
for(i=0;i<MAX;i++) /*The Write Style is 'wb' */
if(*student[i].name)
if(fwrite(&student[i],sizeof(struct stu_imfo),1,fp)!=1)
printf("Sorry!There is a error when the file be writed! \n");
printf("OK! Your operation is successful! :)\n");
printf("Go on your work and enjoy yourself! :P\n");
printf("\n");
fclose(fp);
}
/*****************************************************************************************/
/*Sub Function of Open the File*/
void load(void)
{
FILE *fp;
int i;
if((fp=fopen("stu_imfo","rb"))==NULL)
{
printf("Sorry!Can not open the file! \n");
return;
}
init_list();
for(i=0;i<MAX;i++)
if(fread(&student[i],sizeof(struct stu_imfo),1,fp)!=1)
{
if(feof(fp)) break;
printf("Sorry!Can not read the file! \n");
}
fclose(fp);
printf("OK!You have opened the File which name is stu_imfo . :)\n");
printf("The whole information in the file is: \n");
for(i=0;i<MAX;++i) /*Read the date and Display them*/
{
if(student[i].name[0])
{
printf("<==The name is:%s ==>\n",student[i].name);
printf("<==the sex is:%s ==>\n",student[i].sex);
printf("<==Birthday is:%s ==>\n\n",student[i].bir);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -