`

嵌入式之LINUX--C学生管理系统

 
阅读更多

http://blog.csdn.net/liuzongming1988

 

 

#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>

#define LEN sizeof(struct student)

int n;


/*  printf("/**AUTHOR: Lzm  ** 2013-10-28 ****/\n");
//	printf("/**Student score record system****/\n");
//	printf("/**Select what you want to do:****/\n");
//	printf("/***0 : create a document!  ******/\n");
//	printf("/***1 : insert a new record!******/\n");
//	printf("/***2 : delete a record!    ******/\n");
//	printf("/***3 : save the records!  *******/\n");
//	printf("/***4 : Open a exited file! ******/\n");
//	printf("/***5 : quit the system!    ******/\n");
*/

struct student{
  long num;
  float score;
  struct student *next;
};// Don't forget the ";"!!!!!!!!

//1.Create a new chain table list
struct student * creat(void){
  struct student *head;
  struct student *p1,*p2;
  char temp;
  n=0;
  p1=p2=(struct student *)malloc(LEN);/*CREAT A NEW UNIT*/
  printf("Enter school_number and score:\n");
  printf("Enter 0  0 to quit!\n");
  scanf("%ld %f",&p1->num,&p1->score);
  head=NULL;
  while(p1->num !=0)                // if the num is 0,it is the end of the input
  {
    n=n+1;                          //calculate the number of the member in list
    if(n==1)
	head=p1;                    //if it is the first one,give the address to the head
    else 
	p2->next=p1;               //give the new UNIT address to the last UNIT'S next

    p2=p1;                         //p2 is to save the address of the last.
    p1=(struct student *)malloc(LEN);// malloc() a new mem
    printf("Enter school_number and score:\n");
    scanf("%ld %f",&p1->num,&p1->score);
  }

    p2->next=NULL;
    return (head);
}

//2.show a chain table list
void print(struct student *head){
    struct student* p;
    printf("Now ,These %d records are:\n",n);
    p=head;
    if(head!=NULL){
      do{
	printf("num:%-8ld score:%5.1f\n",p->num,p->score);
    	p=p->next;                            //point to the next UNIT
	}while(p!=NULL);
    }
}


//3.delet the member in a chain table list
struct student * del(struct student *head,long num){
    struct student *p1,*p2,*p3;
    if(head==NULL){
	printf("\n list is null\n");
    	goto end;
    };
    p1=head;
    while(num!=p1->num&&p1->next!=NULL){
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->num){
        if(p1==head)
		{
		p3=head;//to free
		head=p1->next;
		}
        else 
		{
		p3=p1;//to free
		p2->next=p1->next;
		}

	free(p3);//free the malloc, free has no return value,it is a void func.

        printf("delete:%ld successful\n",num);
        n=n-1;
    }
    else 
	printf("can't find the student: %ld\n",num);

  end:
    return (head);
}


//4.save the traintable into a file
void save_train(struct student *head){
    struct student *p;
    char address[40];
    FILE *fp;

    if(head==NULL){
	printf("\n list is null\n");
    	goto end;
    };

    printf("Enter the path!\n");
    scanf("%s",&address[0]);
    
    puts(address);//////////////////

    fp = fopen(address,"wb+");// create a new file
    fputs("school_number",fp);
    fputs("      score   ",fp);

     p=head;
    if(head!=NULL){
      do{
	fputc('\n',fp);                    // enter a Enter 
	fprintf(fp,"   %-10ld",p->num);	   //read the num to num
	fprintf(fp,"    %-3.2f",p->score); //read the score to score
    	p=p->next;                            //point to the next UNIT
	}while(p!=NULL);
    }
    printf("save success to %s \n",address);
    fclose(fp);//you should close the file 
  end:
    ;
}

//5.insert a chain table list  from little to big
struct student *insert(struct student *head,struct student *stu){
    struct student *p0,*p1,*p2;
    p1=head;
    p0=stu;

   if(head==NULL){
      head = p0; p0->next=NULL;
   }
   else{
      while((p0->num > p1->num)&&(p1->next!=NULL))
		{
		   p2=p1;
		   p1=p1->next;
		}
	if(p0->num  <=  p1->num){
            if(head == p1) head = p0;
            else p2->next=p0;
           p0->next = p1;
        }
        else{//That is p1->next == NULL
	   p1->next=p0;
	   p0->next=NULL;	
	}
	n=n+1;
   }
   return head;
}

//6.print the head messages!!!
void print_message(){
	printf("/**AUTHOR: Lzm  ** 2013-10-28 ****/\n");
	printf("/**Student score record system****/\n");
	printf("/**Select what you want to do:****/\n");
	printf("/***0 : create a document!  ******/\n");
	printf("/***1 : insert a new record!******/\n");
	printf("/***2 : delete a record!    ******/\n");
	printf("/***3 : save the records!  *******/\n");
	printf("/***4 : Open a exited file! ******/\n");
	printf("/***5 : quit the system!    ******/\n");
}


//7.import a file as chaintable list
struct student * open_chain(void){

  struct student *head;
  struct student *p1,*p2;
  FILE *fp;

  char address[40],a[20];

   printf("Enter the path!\n");
   scanf("%s",&address[0]);

   fp = fopen(address,"rb");// read a file
   if(fp == NULL) return 0;
   if(!feof(fp)){
	fscanf(fp,"%s",&a[0]);
        fscanf(fp,"%s",&a[0]);
	}
   n=0;  
   p1=p2=(struct student *)malloc(LEN);/*CREAT A NEW UNIT*/
   head=NULL;

  while(!feof(fp)){
        fscanf(fp,"%ld",&p1->num);
        fscanf(fp,"%f",&p1->score);
    n=n+1;                          //calculate the number of the member in list
    if(n==1)
	head=p1;                    //if it is the first one,give the address to the head
    else 
	p2->next=p1;               //give the new UNIT address to the last UNIT'S next

    p2=p1;                         //p2 is to save the address of the last.
    p1=(struct student *)malloc(LEN);// malloc() a new mem
  }

    p2->next=NULL;
    printf("read ok!");
    close(fp);
    return (head);
}
//the main
int main(){ 
  struct student *p,*stu;
  long int num;

  char select = -1;
  char insert_quit=0;
  char delete_quit= 0;

  print_message();
  scanf("%d",&select);
  putchar('\n');

  while(1)
  {// main while
  	switch (select)
  	{
  	  case 0 :  p=creat();   //create
                    break;
	
  	  case 1 :  {            //insert
			 stu = (struct student *)malloc(LEN);
 			 printf("Enter the num and score:\n");
			  printf("Enter 0  0 to quit!\n");
 			 scanf("%ld%f",&stu->num,&stu->score);
 			 while(stu->num !=0){
 			 	 p=insert(p,stu);////////////////
 				 stu = (struct student *)malloc(LEN);
 				 printf("Input the num and score:\n");
  				 scanf("%ld%f",&stu->num,&stu->score);
 			  };
			break;
			}
	
  	  case 2 :  printf("Enter the num:\n");    //delete  
		    printf("Enter 0 to quit\n");        
		      scanf("%ld",&num);
  	            while(num !=0){
  		      		p=del(p,num);
  		      		print(p);
				printf("Put into the num:\n");
				scanf("%ld",&num);
			}
		      break;
	
  	  case 3 :  save_train(p);
			goto step1;
			break;    //save

  	  case 4 :  p=open_chain();
			break;


	  case 5 :
          default: goto endm;
	
  	}
	
  	select = -1;
	system("clear");
	print_message();
	print(p);

    step1:
	printf("/**Select what you want to do!****/\n");
  	scanf("%d",&select);
  	putchar('\n');

  }// end of main while
  endm:
//
  return 0;
}



 

分享到:
评论

相关推荐

    学生管理系统(linux环境)

    嵌入式开发培训课程,c基础和c高级项目实训。

    C语言数据结构项目---学生信息管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    linux环境下shell和C语言分别开发学生管理系统.zip

    嵌入式Linux开发

    C语言学生管理系统

    用linux C编写的一个学生信息管理系统。 运用到了C语言中文件的知识和数据结构中链表的知识

    Linux下用C语言实现学生信息管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    C艹大作业-基于Qt-C++的简易学生成绩管理系统.zip

    操作系统:LInux、IOS、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络...

    学生成绩管理系统 - 华中科技大学C语言课程设计,Qt实现,2016年寒假.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    linux下的学分教员管理系统

    用于学生,教师,管理员登录并进行对学生的管理,学生登录可查看自己的信息,教师登录可管理和查看自己及学生的信息,管理员登录可任意对学生教师操作,登录密码请查看里面的文件。管理员登录用户名及密码为adm,123....

    C语言学生信息管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    C语言学生成绩管理系统.zip

    这个采用C语言开发的项目是一个多功能的软件应用程序。它旨在提供一个高效、可靠的解决方案,...它的跨平台性、可定制性和高性能使其成为一个理想的选择,无论是进行系统编程、嵌入式开发还是进行科学计算和数据处理。

    C语言学生成绩管理系统源码.zip

    这个采用C语言开发的项目是一个多功能的软件应用程序。它旨在提供一个高效、可靠的解决方案,...它的跨平台性、可定制性和高性能使其成为一个理想的选择,无论是进行系统编程、嵌入式开发还是进行科学计算和数据处理。

    嵌入式课程设计任务书.

    嵌入式IC卡课程设计任务书,基于ARM S3C2410开发平台和嵌入式Linux系统,完成校园IC卡数据库管理系统的开发,IC智能卡可供学生用于校园内部处理杂务,购买食品、饮料、书本,

    c语言课设之学生信息管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    学生管理系统

    嵌入式培训高级C的项目学生管理系统代码,运用GCC+GDB,在Linux系统下运行。

    嵌入式工程师必知必会 (完整高清中文PDF版)

    c++、c、汇编语言在小型嵌入式系统中 61 3.8 防盗版开发工具简介 65 3.9 基于avr微控制器和免费工具的8位嵌入式项目实例 67 第4章 自学自顶向下的设计方法(大型嵌入式系统) 93 .4.1 目标读者 93 4.2 嵌入式...

    C语言项目设计

    源程序代码 习题与课件 综合案例-学生成绩管理程序 俄罗斯方块游戏 嵌入式系统开发基础 嵌入式Linux C语言应用程序设计与实践课件及代码

    C语言班级学生成绩管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    C语言课设 学生信息成绩管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

    C语言写的学生学籍管理系统.zip

    操作系统:LInux、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信...

Global site tag (gtag.js) - Google Analytics