| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 477 人关注过本帖
标题:程序在VC6.0下能正确运行,在TC下却运行错误。
只看楼主 加入收藏
RO09
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-2
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
程序在VC6.0下能正确运行,在TC下却运行错误。
请大家帮帮我,程序是在64位VC写的,但是要交作业了,老师要求是TC,
1 我想问问程序错在哪里?
2 此程序后面读取文件中学生信息时候会有乱码出现,应该怎么操作?
# include "stdio.h"
# include "stdlib.h"
# include "string.h"
struct node{
    int number;
    char name[20];
    char type;
    int age;
    int math;
    int english;
    int Clanguage;
    int structure;
    int sports;
    int total;
    int average;
    }student[30];
struct node temp;
void menu()
    {
    system("cls");
    printf("\t\t** Welcome to use the Program! **\t\n");
    printf("\t\t* * * * * * * * * * * * * * * * *\t\n");
    printf("\t\t********   *   **   *    ********\t\n");
    printf("\t\t********   [1]  input    ********\t\n");
    printf("\t\t********   [2]  find     ********\t\n");
    printf("\t\t********   [3]  insert   ********\t\n");
    printf("\t\t********   [4]  delete   ********\t\n");
    printf("\t\t********   [5]  print    ********\t\n");
    printf("\t\t********   [6]  save     ********\t\n");
    printf("\t\t********   [7]  read     ********\t\n");
    printf("\t\t********   [8]  exit     ********\t\n");
    printf("\t\t********   *   **    *   ********\t\n");
    printf("\t\t* * * * * * * * * * * * * * * * *\t\n");
    printf("\t\t choose(1-8):");
    }

void input(int c)
{
    int i;
    for(i=1;i<4;i++)
    {
    printf("please input %d student's number:",i);
    scanf("%d",&student[i].number);
    printf("please input %d student's name:",i);
    scanf("%s",student[i].name);
    getchar();
    printf("please input %d student's age:",i);
    scanf("%d",&student[i].age);
    flushall();
    printf("please input %d student's type:",i);                     
    scanf("%c",&student[i].type);            
    flushall();
    printf("please input %d student's math:",i);
    scanf("%d",&student[i].math);
    printf("please input %d student's english:",i);
    scanf("%d",&student[i].english);
    printf("please input %d student's Clanguage:",i);
    scanf("%d",&student[i].Clanguage);
    printf("please input %d student's structure:",i);
    scanf("%d",&student[i].structure);
    printf("please input %d student's sports:",i);
    scanf("%d",&student[i].sports);
    student[i].total=student[i].math+student[i].english+student[i].Clanguage+student[i].structure+student[i].sports;
    student[i].average=student[i].total/5;
    }
}
void find(int c)
{
    int n,m,i,j,l;
    char k[20];
    system("cls");
    printf("number find 1:\n");
    printf("name find 2:\n");
    printf("please choose(1-2):");
    scanf("%d",&n);
    if (n==1)
    {   
    printf("you choose number find\n");
    printf("please input number:");
        scanf("%d",&m);
        for(i=1;i<=c;i++)
        {
        if(student[i].number==m)
            {
        printf("************************************\n");
        printf("number:%d\n",student[i].number);
        printf("name:%s\n",student[i].name);
        printf("age:%d\n",student[i].age);
        printf("type:%c\n",student[i].type);
        printf("math:%d\n",student[i].math);
        printf("english:%d\n",student[i].english);
        printf("Clanguage:%d\n",student[i].Clanguage);
        printf("structure:%d\n",student[i].structure);
        printf("sports:%d\n",student[i].sports);
        printf("total:%d\n",student[i].total);
        printf("average:%d\n",student[i].average);
        printf("************************************\n");
                getchar();
            }
        
        }
     }
    else
        if (n==2)
        {
        getchar();
        printf("you choose name find");
        printf("please input name:");
            fgets(k,20,stdin);
            l=strlen(k);
            k[l-1]='\0';   
        for(j=1;j<=c;j++)
            {
        if(strcmp(k,student[j].name)==0)
                {
            printf("*********************************\n");
            printf("number:%d\n",student[j].number);
            printf("name:%s\n",student[j].name);
            printf("age:%d\n",student[j].age);
            printf("type:%c\n",student[j].type);
            printf("math:%d\n",student[j].math);
            printf("english:%d\n",student[j].english);
            printf("Clanguage:%d\n",student[j].Clanguage);
            printf("structure:%d\n",student[j].structure);
            printf("sports:%d\n",student[j].sports);
            printf("total:%d\n",student[j].total);
            printf("average:%d\n",student[j].average);
            printf("*********************************\n");
                }
      
           }
        }
   else
   {
   getchar();
    }
    system("pause");
   
}

void insert(int c)
    {
    int i,j;
    system("cls");
    printf("please input student's number:");
    scanf("%d",&temp.number);
    printf("please input student's name:");
    scanf("%s",temp.name);
    printf("please input student's age:");
    scanf("%d",&temp.age);
    flushall();
    printf("please input student's type:");
    scanf("%c",&temp.type);
    flushall();
    printf("please input student's math:");
    scanf("%d",&temp.math);
    printf("please input student's english:");
    scanf("%d",&temp.english);
    printf("please input student's Clanguage:");
    scanf("%d",&temp.Clanguage);
    printf("please input student's structure:");
    scanf("%d",&temp.structure);
    printf("please input student's sports:");
    scanf("%d",&temp.sports);
    temp.total=temp.math+temp.english+temp.Clanguage+temp.structure+temp.sports;
    temp.average=temp.total/5;
    for (i=0;i<c;i++)
    {
        if (temp.number<student[i].number)
        {
            for (j=c;j>i;j--)
            {
            student[j].number=student[j-1].number;
            strcpy(student[j].name,student[j-1].name);
            student[j].age=student[j-1].age;
            student[j].type=student[j-1].type;
            student[j].math=student[j-1].math;
            student[j].english=student[j-1].english;
            student[j].Clanguage=student[j-1].Clanguage;
            student[j].structure=student[j-1].structure;
            student[j].sports=student[j-1].sports;
            student[j].total=student[j-1].total;
            student[j].average=student[j-1].average;
            }
            student[j].number=temp.number;
            strcpy(student[j].name,temp.name);
            student[j].age=temp.age;
            student[j].type=temp.type;
            student[j].math=temp.math;
            student[j].english=temp.english;
            student[j].Clanguage=temp.Clanguage;
            student[j].structure=temp.structure;
            student[j].sports=temp.sports;
            student[j].total=temp.total;
            student[j].average=temp.average;
            break;
        }
    }
    if(i>=c)
        {
            student[i].number=temp.number;
            strcpy(student[j].name,temp.name);
            student[i].age=temp.age;
            student[i].type=temp.type;
            student[i].math=temp.math;
            student[i].english=temp.english;
            student[i].Clanguage=temp.Clanguage;
            student[i].structure=temp.structure;
            student[i].sports=temp.sports;
            student[i].total=temp.total;
            student[i].average=temp.average;
        }
}
void deletel(int c)
{
    int i,j,n,k;
    char name[20];
    printf("number delete(1):\n");
    printf("name delete(2):\n");
    scanf("%d",&k);
    if(k==1)
    {
        printf("please input number:\n");
        scanf("%d",&n);
        for(i=0;i<c;i++)
        {
        if(student[i].number==n)
            {
                c=c-1;
                for(j=i;j<c;j++)
                {
                student[j].number=student[j+1].number;
                strcpy(student[j].name,student[j+1].name);
                student[j].age=student[j+1].age;
                student[j].type=student[j+1].type;
                student[j].structure=student[j+1].structure;
                student[j].english=student[j+1].english;
                student[j].Clanguage=student[j+1].Clanguage;
                student[j].structure=student[j+1].structure;
                student[j].sports=student[j+1].sports;
                student[j].total=student[j+1].total;
                student[j].average=student[j+1].average;
                }
            }
        }
    }
    else
    if(k==2)
    {
        getchar();
        printf("please input student name:\n");
        for(i=0;i<c;i++)
        {
            if(strcmp(name,student[i].name)==0)
            {
                for(j=i;j<c;j++)
                {
                student[j].number=student[j+1].number;
                strcpy(student[j].name,student[j+1].name);
                student[j].type=student[j+1].type;
                student[j].age=student[j+1].age;
                student[j].structure=student[j+1].structure;
                student[j].english=student[j+1].english;
                student[j].Clanguage=student[j+1].Clanguage;
                student[j].structure=student[j+1].structure;
                student[j].sports=student[j+1].sports;
                student[j].total=student[j+1].total;
                student[j].average=student[j+1].average;
                }
            }
        }
    }
    else
    {
        getchar();
    }

}
void print(int c)
{
    int i;
    system("cls");
    for(i=1;i<=c;i++)
    {
        printf("***************************************\n");
        printf("number:%d\n",student[i].number);
        printf("name:%s\n",student[i].name);
        printf("age:%d\n",student[i].age);
        printf("type:%c\n",student[i].type);
        printf("math grade:%d\n",student[i].math);
        printf("english grade:%d\n",student[i].english);
        printf("Clanguage grade:%d\n",student[i].Clanguage);
        printf("structure grade:%d\n",student[i].structure);
        printf("sports grade:%d\n",student[i].sports);
        printf("total:%d\n",student[i].total);
        printf("average:%d\n",student[i].average);
        printf("***************************************\n");
    }
    printf("Press any key to continue .................\n");
    getchar();
    getchar();
}

void   save(int c)
    {
      int i;
      FILE *fp;
      if((fp=fopen("studentdate.txt","a+"))==NULL)
      {
      printf("File open error! \n");
      exit(0);
      }
      for(i=1;i<=c;i++)
      fprintf(fp,"%d %s %c %d %d %d %d %d %d %d %d\n",student[i].number,student[i].name,student[i].type,student[i].age,student[i].math,student[i].english,student[i].Clanguage,student[i].structure,student[i].sports,student[i].total,student[i].average);
      if(fclose(fp))
      {
       printf("Can not close the file! \n");
       exit(0);
      }
      system("pause");
    }
void   read(int c)
    {
      FILE *fp;
      int  i;
      if((fp=fopen("studentdate.txt","a+"))==NULL)
     {
       printf("File open error! \n");
       exit(0);
      }
     printf("number name type age math english Clanguage tructure sports total average \n");
     for(i=1;i<=c;i++)
     {
         fseek(fp,i*sizeof(struct node),0);
         fread(&student[i],sizeof(struct node),3,fp);
         printf("%d\t%s\t%c\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n",student[i].number,student[i].name,student[i].type,student[i].age,student[i].math,student[i].english,student[i].Clanguage,student[i].structure,student[i].sports,student[i].total,student[i].average);
         getchar();
    }

     if(fclose(fp))
     {
        printf("Can not close the file! \n");
        exit(0);
     }
     system("pause");
    }
void error()
{
    printf("Error!!!\n");
    printf("please choose (1-8):\n");
    printf("press Enter to continue....\n");
    getchar();
    getchar();
}
int main()
{

  int    n,c=0;
  while(1)
     {
  menu();
    printf("please input your choose:");
    scanf("%d",&n);
    switch(n)
       {

        case 1:input(c);c=c+3;break;
            case 2:find(c);break;
            case 3:insert(c);++c;break;
            case 4:deletel(c);--c;break;
            case 5:print(c); break;
            case 6:save(c);break;
            case 7:read(c);break;
            case 8:break;
            default:error();break;

        }
    }
 }
搜索更多相关主题的帖子: english system 中学生 老师 
2011-06-02 21:47
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:7 
是在抱歉  我这里只有VC

                                         
===========深入<----------------->浅出============
2011-06-02 21:51
RO09
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-2
收藏
得分:0 
回复 2楼 laoyang103
没事,我主要是想看看那里的问题,这个程序很简单我觉得不会是软件的功能问题。VC能运行,在TC菜单出来就一直要求我选择。
2011-06-02 21:54
gupiao175
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:40
帖 子:1787
专家分:7527
注 册:2007-6-27
收藏
得分:7 
以下是引用RO09在2011-6-2 21:54:03的发言:

没事,我主要是想看看那里的问题,这个程序很简单我觉得不会是软件的功能问题。VC能运行,在TC菜单出来就一直要求我选择。

TC下测试过了。确实是这样。老是出现ERROR错误提示!

Q:1428196631,百度:开发地 即可找到我,有事请留言!
2011-06-03 01:38
RO09
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-6-2
收藏
得分:0 
回复 4楼 gupiao175
谢谢版主
2011-06-03 11:40
快速回复:程序在VC6.0下能正确运行,在TC下却运行错误。
数据加载中...
 
   



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

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