佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1073|回复: 7

这个怎样做?pogrammer进来下

[复制链接]
发表于 7-8-2009 02:05 PM | 显示全部楼层 |阅读模式
我朋友的assignment来的

你们会做么?

很多error下

我看了头大

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#include <stdio.h>
#include <conio.h>

struct car
{

        char carModel [20];
        int engineCapacity;
        int year;
        float evalScore;
};
typedef struct Car Vehicle;
Vehicle automobile [10];

main()
{
        void InputRec(Vehicle S[]);
        void ListRec(Vehicle S[]);

        int choice;

        do
        {
            clrscr();
            gotoxy(18,5);
            printf("Selection Menu");
            gotoxy(18,6);
            printf("******************");
            gotoxy(18,8);
            printf("1.Input Car Model ");
            gotoxy(18,10);
            printf("2.Print Car Model Listing and Highest Evaluation Score Records");
            gotoxy(18,12);
            printf("0.Exit Program");

            gotoxy(30,16);
            printf("Enter your selection:");
            scanf("%d",&choice);

            switch(choice)
            {
                case 1: InputRec(automobile);
                        getch();
                        break;

                case 2: ListRec(automobile);
                        getch();
                        break;

                case 0: clrscr();
                        gotoxy(30,24);
                        printf("~**End of Program**~");
                        getch();
                        exit(1);
                }
            }while (choice>=0 || choice <=2);

            gotoxy(30,24);
            printf("Press ENTER to continue");

            getch();
}

void InputRec(Vehicle S[])
{
        FILE *fin;
        float temp;
        int index;

        fin=fopen ("c:/car.txt","w");

        if(fin==NULL)

        {
                printf ("CANNOT create New File!");
                exit(1);
        }

        for(index=0; index<=9; index++)
        {
                clrscr();
                gotoxy(20,5);
                printf("Input Car Models");
                gotoxy(20,6);
                printf ("********************");
                gotoxy(20,8);
                printf("Record No: %d",index+1);

                gotoxy(20,12);
                printf("CarModelNo     :");
                gotoxy(20,14);
                printf("engineCapacity   :");
                gotoxy(20,16);
                printf("year:");
                gotoxy(20,18);
                printf("Evaluation score :");

                gotoxy(38,12);
                gets(S[index].CarModelNo);
                fflush(stdin);
                gotoxy(38,14);
                scanf("%d",&S[index].engineCapacity);
                fflush(stdin);
                gotoxy(38,16);
                scanf("%d",&S[index].year);
                gotoxy(38,18);
                scanf("%f",&temp);
                S[index].evalScore=temp;
        }

        for(index=0; index<=9; index++)
        {

        fprintf(fin, "%-5s",S[index].CarModelNo);
        fprintf(fin, "%-20d",S[index].engineCapacity);
        fprintf(fin, "%-40d",S[index].year);
        fprintf(fin, "%8.2f\n",S[index].evalScore);
        }

        fclose(fin);
}

void ListRec(Vehicle S[])
{

        FILE *fout;
        int index;
        int low;

        fout=fopen("c:/Car.txt","r");

        if (fout==NULL)
        {
                printf ("CANNOT open file!");
                exit(1);
        }

        for(index=0; index<=9; index++)
        {

                fgets(fout, "%s",&S[index].CarModelNo);
                fscanf("%d", &S[index].engineCpacity,sizeof(S[index].engineCapacity),fout);
                fscanf("%d", &S[index].year,sizeof(S[index].year),fout);
                fscanf(fout,"%f",&S[index].evalScore);
        }

        clrscr();
        gotoxy(25,1);
        printf("Car Model List");
        gotoxy(25,2);
        printf("**************");
        gotoxy(1,4);
        printf("%-16s%-37d%-15s\n","CarModelNo","engineCpacity and year","Evaluation score");
        for(index=0; index<=9;index++)
        {

        printf("%-13d",S[index].CarModelNo);
        printf("%-40s",S[index].engineCpacity);
        printf("%-10.2f\n",S[index].evalScore);
        printf("%-20c%-35s\n",255,S[index].year);
        }

        for(index=1; index<=80; index++)
        {
                printf("%c",196);
        }

        gotoxy(30,24);
        printf("Press ENTER to continue");
        getch();

        low=0;

        for(index=1; index<=9; index++)
        {
                if(S[index].evalScore>S[low].evalScore)
                low=index;
        }


        clrscr();
        printf("The Highest Evaluation Score Record is :");

        printf("\nCarModelNo           :%s",S[low].CarModelNo);
        printf("\nengineCapacity                  :%d",S[low].engineCapacity );
        printf("\nyear               :%d",S[low].year);
        printf("\nevalScore       :%6.2f",S[low].evalScore);

        fclose(fout);
}
回复

使用道具 举报


ADVERTISEMENT

发表于 7-8-2009 04:35 PM | 显示全部楼层
请详细描述你的代码要做些什么,以及出现的error。我们虽然愿意帮你,但试跑、除虫以及猜测你的问题并不是我们的义务。

还有,
你们会做么?

这句很串一下。

[ 本帖最后由 geekman 于 7-8-2009 04:36 PM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 7-8-2009 04:38 PM | 显示全部楼层

回复 2# geekman 的帖子

没有我不是这个意思
~~~~~~~~~~
回复

使用道具 举报

发表于 7-8-2009 08:50 PM | 显示全部楼层
赞同 geekman 说的, 发问前将你的 coding 解释清楚, 列出 error statement, 以及你对error 的看法, 这个将使愿意帮助你的人不会因为看到一堆不明不白, 没有 comment 的 code, 然后显掉, 就不想帮你了。

还有

typedef struct Car Vehicle;
Vehicle automobile [10];

main()
{
        void InputRec(Vehicle S[]);
        void ListRec(Vehicle S[]);


没有 return type 的 main ?

太不标准了了一点
回复

使用道具 举报

 楼主| 发表于 7-8-2009 10:49 PM | 显示全部楼层
Compiler: Default compiler
Executing  gcc.exe...
gcc.exe "XXX.c" -o "XXX.exe"    -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
XXX.c: In function `InputRec':
XXX.c:50: error: invalid use of undefined type `struct Car'
XXX.c:50: error: dereferencing pointer to incomplete type
XXX.c:53: error: invalid use of undefined type `struct Car'
XXX.c:53: error: dereferencing pointer to incomplete type
XXX.c:56: error: invalid use of undefined type `struct Car'
XXX.c:56: error: dereferencing pointer to incomplete type
XXX.c:59: error: invalid use of undefined type `struct Car'
XXX.c:59: error: dereferencing pointer to incomplete type

XXX.c:65: error: invalid use of undefined type `struct Car'
XXX.c:65: error: dereferencing pointer to incomplete type
XXX.c:66: error: invalid use of undefined type `struct Car'
XXX.c:66: error: dereferencing pointer to incomplete type
XXX.c:67: error: invalid use of undefined type `struct Car'
XXX.c:67: error: dereferencing pointer to incomplete type
XXX.c:68: error: invalid use of undefined type `struct Car'
XXX.c:68: error: dereferencing pointer to incomplete type

XXX.c: In function `ListRec':
XXX.c:92: error: invalid use of undefined type `struct Car'

XXX.c:92: error: dereferencing pointer to incomplete type
XXX.c:92: warning: passing arg 1 of `fgets' from incompatible pointer type
XXX.c:92: warning: passing arg 2 of `fgets' makes integer from pointer without a cast
XXX.c:93: error: invalid use of undefined type `struct Car'
XXX.c:93: error: dereferencing pointer to incomplete type

XXX.c:93: error: invalid use of undefined type `struct Car'
XXX.c:93: error: dereferencing pointer to incomplete type
XXX.c:93: warning: passing arg 1 of `fscanf' from incompatible pointer type
XXX.c:94: error: invalid use of undefined type `struct Car'
XXX.c:94: error: dereferencing pointer to incomplete type
XXX.c:94: error: invalid use of undefined type `struct Car'
XXX.c:94: error: dereferencing pointer to incomplete type
XXX.c:94: warning: passing arg 1 of `fscanf' from incompatible pointer type
XXX.c:95: error: invalid use of undefined type `struct Car'
XXX.c:95: error: dereferencing pointer to incomplete type
XXX.c:108: error: invalid use of undefined type `struct Car'
XXX.c:108: error: dereferencing pointer to incomplete type
XXX.c:109: error: invalid use of undefined type `struct Car'
XXX.c:109: error: dereferencing pointer to incomplete type
XXX.c:110: error: invalid use of undefined type `struct Car'
XXX.c:110: error: dereferencing pointer to incomplete type
XXX.c:111: error: invalid use of undefined type `struct Car'
XXX.c:111: error: dereferencing pointer to incomplete type
XXX.c:127: error: invalid use of undefined type `struct Car'
XXX.c:127: error: dereferencing pointer to incomplete type
XXX.c:127: error: invalid use of undefined type `struct Car'
XXX.c:127: error: dereferencing pointer to incomplete type
XXX.c:135: error: invalid use of undefined type `struct Car'
XXX.c:135: error: dereferencing pointer to incomplete type

XXX.c:136: error: invalid use of undefined type `struct Car'

XXX.c:136: error: dereferencing pointer to incomplete type
XXX.c:137: error: invalid use of undefined type `struct Car'
XXX.c:137: error: dereferencing pointer to incomplete type
XXX.c:138: error: invalid use of undefined type `struct Car'
XXX.c:138: error: dereferencing pointer to incomplete type
XXX.c: At top level:
XXX.c:13: error: storage size of `automobile' isn't known
回复

使用道具 举报

发表于 7-8-2009 10:52 PM | 显示全部楼层
struct car
{

        char carModel [20];
        int engineCapacity;
        int year;
        float evalScore;
};
typedef struct Car Vehicle;

注意大小写
回复

使用道具 举报

Follow Us
 楼主| 发表于 7-8-2009 10:57 PM | 显示全部楼层

回复 6# onlylonly 的帖子

谢谢你
我没看到tim
~~~~~~~
回复

使用道具 举报

发表于 13-8-2009 12:07 PM | 显示全部楼层
帮不到你。。。哈哈。。。很久没有动 C 了。。。vb6 我就可以帮得上
回复

使用道具 举报


ADVERTISEMENT

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 11-5-2024 04:12 PM , Processed in 0.066817 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表