标题:有的程序在VC++可以运行,在turboC不能,他们的差异在哪里?
只看楼主
Lzssdxy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-2-24
结帖率:100%
已结贴  问题点数:20 回复次数:3 
有的程序在VC++可以运行,在turboC不能,他们的差异在哪里?
C程序 学生管理系统
#include "stdio.h"
#include"stdlib.h"
#include"string.h"


typedef struct student//定义学生
{
    char name[10];
    int number;
    char sex[2];
    int math;
    int eglish;
    int clanguge;
    int average;
}student;

typedef struct unit//定义接点
{
    student date;
    struct unit *next;
}unit;


unit* build()//建立链表并返回指针
{
    unit *p;
    if((p=(unit*)malloc(sizeof(unit)))==NULL)
     { printf("=>初始化失败!");
         return 0;
     }
    else
     {p->next=NULL;
         p->date.number=0;//头结点存放学生人数
      printf("初始化成功!\n");
      return p;
     }
}


void add(unit *head)//增加学生
{
    unit *p,*q;
    int m,n=0;
    q=head->next;
    p=(unit*)malloc(sizeof(unit));
    printf("=>请输入新生姓名!\n");
    gets(p->date.name);fflush(stdin);
    printf("=>请输入学号!\n");
    while(n==0)
    {
        scanf("%d",&m);fflush(stdin);
        if(q==NULL) n=1;
        while(q)
        {
            if(q->date.number==m)
            {
               printf("=>你输入的学号与已有同学的学号相同,请重新输入!\n");
               q=head->next;
               break;
            }
        
            else
            {
               q=q->next;
               if(q==NULL) n=1;
            }
        }
    }
    p->date.number=m;
    printf("=>请输入性别!\n");
    gets(p->date.sex);fflush(stdin);
    printf("=>请输入数学成绩\n");
    scanf("%d",&m);fflush(stdin);
    p->date.math=m;
    printf("=>请输入英语成绩\n");
    scanf("%d",&m);fflush(stdin);
    p->date.eglish=m;
    printf("=>请输入c语言成绩\n");
    scanf("%d",&m);fflush(stdin);
    p->date.clanguge=m;
    p->date.average=(p->date.math+p->date.eglish+p->date.clanguge);
    q=head->next;
    head->next=p;
    p->next=q;
    head->date.number++;
}
   

void deletion(unit *head)//删除一名学生
{
    unit *p=head->next,*q=head;
    char N[10];
    printf("=>请输入你想删除的学生姓名!\n");
    gets(N);fflush(stdin);
    if(p==NULL)
    printf("=>系统无学生可删除!\n");
    while(p)
    {
        if(strcmp(p->date.name,N)==0)
        {
            q->next=p->next;
            head->date.number--;
            printf("=>删除%s成功!\n",p->date.name);
            free(p);
            break;
        }
        else
        {
            p=p->next;
            q=q->next;
            if(p==NULL)
            printf("=>你要删除的学生不存在,删除失败!\n");
        }
    }

}


int display(unit *head)//显示学生信息
{
    unit *p=head->next;
    int m,n=0;
    char N[10];
    if(p==NULL)
    {
        printf("=>系统无学生!\n");
        return 0;
    }
    while(n==0)
    {
        printf("******************************************************************************\n");
        printf("=>请选择你的操作!\n");
        printf("=>\t\t\t1.显示所有\t2.按姓名查找\n\t\t\t3.按学号查找\t4.返回主菜单\n");
        scanf("%d",&m);
        fflush(stdin);
        switch(m)
        {
            case 1:printf("\n=>该系统拥有%d名学生!\n\n",head->date.number);
                   p=head->next;
                   printf("\t姓名\t学号\t性别\t数学\t英语\tc语言\t综合\n\n");
                   while(p)
                    {
                        printf("\t%s\t%d\t%s\t%d\t%d\t%d\t%d\n",p->date.name,p->date.number,p->date.sex,p->date.math,
                        p->date.eglish,p->date.clanguge,p->date.average);
                        p=p->next;
                    }
                    break;
            case 2:printf("=>请输入查找姓名!\n");
                   gets(N);
                   fflush(stdin);
                   p=head->next;
                  while(p)
                   {
                       if(strcmp(p->date.name,N)==0)
                    {
                        printf("\t姓名\t学号\t性别\t数学\t英语\tc语言\t综合\n");
                        printf("\t%s\t%d\t%s\t%d\t%d\t%d\t%d\n",p->date.name,p->date.number,p->date.sex,p->date.math,
                        p->date.eglish,p->date.clanguge,p->date.average);
                        break;
                    }
                    else
                    {
                        p=p->next;
                        if(p==NULL)
                        printf("=>你要查的学生不存在!");
                    }
                   }
                    break;
              case 3: printf("=>请输入查找学号!\n");
                   scanf("%d",&m);
                   fflush(stdin);
                  p=head->next;
                  while(p)
                   {
                       if(p->date.number==m)
                    {
                        printf("\t姓名\t学号\t性别\t数学\t英语\tc语言\t综合\n");
                        printf("\t%s\t%d\t%s\t%d\t%d\t%d\t%d\n",p->date.name,p->date.number,p->date.sex,p->date.math,
                        p->date.eglish,p->date.clanguge,p->date.average);
                        break;
                    }
                    else
                    {
                        p=p->next;
                        if(p==NULL)
                        printf("=>你要查的学生不存在!\n");
                    }
                   }
                    break;
             case 4:n=1;break;
        }
    }
    return 1;
}
                              



int range(unit *head)//排序
{
    unit *p=head,*q=head->next;
    int n,i,m=head->date.number;
    printf("*******************************************************************************\n");
    printf("\t\t\t1.按学号\t2.按成绩\n\n");
    printf("=>请选择操作!\n》");
    scanf("%d",&n);
    fflush(stdin);
    if(q==NULL)
    { printf("=>无学生可排序!\n");
        return 0;
    }
    switch(n)
    {
        case 2:for(i=0;i<m;i++)//按总分排序
                {
                    p=head;q=head->next;
                    while(q->next)
                    {
                        if((q->date.average)<(q->next->date.average))
                        {
                            p->next=q->next;
                            p=p->next;
                            q->next=p->next;
                            p->next=q;
                        }
                        else
                        {
                            p=p->next;q=q->next;
                        }
                    }
                }
                break;

         case 1:for(i=0;i<=m;i++)//按学号排序
                {
                    p=head;q=head->next;
                    while(q->next)
                    {
                        if((q->date.number)>(q->next->date.number))
                        {
                            p->next=q->next;
                            p=p->next;
                            q->next=p->next;
                            p->next=q;
                        }
                        else
                        {
                            p=p->next;q=q->next;
                        }
                    }
                }
                break;
    }
    printf("=>排序成功!\n");
    return 1;
}




void menu()
{
    printf("\n********************************* 主菜单 ***************************************\n");
   
    printf("\t\t\t1.新建系统\t2.添加学生\n\t\t\t3.删除学生\t4.查看信息\n\t\t\t5.排列顺序\t6.读取信息\n\t\t\t7.保存信息\t8.退出系统\n");
    printf("=>请选择你的操作!\n");
}


int save(unit *head)//保存
{
    FILE *fp;
    unit *p;
    p=head;
    if((fp=fopen("d:\\学生","wb+"))==NULL)
    {
        printf("=>保存失败!");
        return 0;
    }
   while(p)
    {fwrite(&(p->date),sizeof(student),1,fp);
    p=p->next;
    }
    printf("=>保存成功!");
   fclose(fp);
   return 1;
}



unit* read()//读入系统学生信息
{
    int i;
    unit *p,*q,*head;
    FILE *fp;
    if((head=(unit*)malloc(sizeof(unit)))==NULL)
     { printf("=>开辟空间失败!");
         exit(1);
     }
    else
     {
         head->next=NULL;
         head->date.number=0;//头结点存放学生人数
     }
    q=head;
 if((fp=fopen("d:\\学生","rb"))==NULL)
   {printf("=>系统无学生!\n");
    return 0;
    }
 fread(&(q->date),sizeof(student),1,fp);
 for(i=0;i<head->date.number;i++)
 {
     if((p=(unit*)malloc(sizeof(unit)))==NULL)
     { printf("=>读值失败!");
         exit(1);
     }
    fread(&(p->date),sizeof(student),1,fp);
    p->next=q->next;
    q->next=p;
 }
 fclose(fp);
 return head;
}

void main()
{
    int m=0,n, i;
     unit *head;
     printf("********************************************************************************\n\n");
     printf("\t\t\t* 欢迎使用学生成绩管理系统 * \n");
     printf("\n\t\t\t\t\t\t\t\t编译员:岳英明\n\n");
     printf("=>正在读取系统信息......\n");
     if((head=read())==0)
     {
         printf("=>是否新建?\n");
        printf("\t\t\t是(1)\t\t否(2)\n");
           scanf("%d",&i);
           fflush(stdin);
           if(i==1)
             head=build();
           else if(i==2)
             exit(1);
     }
     else
     printf("=>信息导入成功!");
    while(m==0)
    {
        menu();
        scanf("%d",&n);
        fflush(stdin);
     switch(n)
     {
         case 1: head=build();break;
         case 2:add(head);break;
         case 3:deletion(head);break;
         case 4:display(head);break;
         case 5: range(head);break;
         case 6:head=read();if(head!=0) printf("=>读取存盘成功!\n");break;
         case 7:save(head);break;
         case 8:m=1;break;
     }
   }
}
搜索更多相关主题的帖子: next 管理系统 average include return 
2012-06-12 15:49
橘子橙
Rank: 2
等 级:论坛游民
帖 子:7
专家分:11
注 册:2012-6-12
得分:7 
c不好学哦。
2012-06-12 23:16
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
得分:7 
unit? 你确信这在VC里能通过编译?

重剑无锋,大巧不工
2012-06-13 00:22
Lzssdxy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-2-24
得分:0 
回复 3楼 beyondyf
嗯,我从VC++运行过的,
2012-06-13 22:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-371390-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.101426 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved