查看: 1073|回复: 7
|
这个怎样做?pogrammer进来下
[复制链接]
|
|
我朋友的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);
} |
|
|
|
|
|
|
|
发表于 7-8-2009 04:35 PM
|
显示全部楼层
请详细描述你的代码要做些什么,以及出现的error。我们虽然愿意帮你,但试跑、除虫以及猜测你的问题并不是我们的义务。
还有,
这句很串一下。
[ 本帖最后由 geekman 于 7-8-2009 04:36 PM 编辑 ] |
|
|
|
|
|
|
|
楼主 |
发表于 7-8-2009 04:38 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 7-8-2009 08:50 PM
|
显示全部楼层
|
|
|
|
|
|
|
楼主 |
发表于 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;
注意大小写 |
|
|
|
|
|
|
|
楼主 |
发表于 7-8-2009 10:57 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 13-8-2009 12:07 PM
|
显示全部楼层
帮不到你。。。哈哈。。。很久没有动 C 了。。。vb6 我就可以帮得上 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|