Hello all
I have come to you with a problem. I have an assignment where I have to make a program that stores information in Structures and the structures are held in an array. I have been working for day, I'm not a programmer thus it's going slow as hell for me.
Anyway, I get what I believe all the code needed, ready for some debugging an I get an error I cannot fix.
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
gcc.exe maindg.o -o "Project2.exe" -L"C:/Dev-Cpp/lib" -g
maindg.o(.text+0x16f): In function `main':
C:/Dev-Cpp/maindg.c:58: undefined reference to `addCar'
maindg.o(.text+0x22f):C:/Dev-Cpp/maindg.c:79: undefined reference to `showFleet'
maindg.o(.text+0x66e): In function `showCar':
C:/Dev-Cpp/maindg.c:202: undefined reference to `showDate'
maindg.o(.text+0x688):C:/Dev-Cpp/maindg.c:204: undefined reference to `showDate'
collect2: ld returned 1 exit status
make.exe: *** [Project2.exe] Error 1
Execution terminated
My code is
#include <stdio.h>
#include <string.h>
typedef struct{
int year;
int month;
int day;
}Date;
typedef struct{
char make[10];
Date manufactureDate;
Date purchaseDate;
double purchasePrice;
}Car;
void getDate(Date* dateimp);
void addCar(Car* newcar);
void readFleet(Car fleet[]);
void saveFleet(Car fleet[]);
void showFleet(Car fleet[]);
void showCar(Car* shcar);
void showDate(Date* sdate);
int main(void)
{
int choice;
int i;
Car fleet[11];
strcpy(fleet[0].make, "SNT");
printf("New Millennium Car Sales\n");
printf("------------------\n");
printf("1.Add a car\n");
printf("2.Delete last added car\n");
printf("3.Display fleet on screen\n");
printf("4.Save fleet to file\n");
printf("5.Read fleet to file\n");
printf("6.Exit program\n\n");
printf("Enter the number of the choice you would like to make and press enter>");
if(choice==1||choice==2||choice==3||choice==4||choice==5||choice==6)
scanf("%d", &choice);
else(printf("Input number must be from 1 to 6"));
scanf("%d", &choice);
if(choice == 1) /*choice1*/
{
i=-1;
do{++i;}
while(strcmp(fleet[i].make, "SNT"));
if(i<10)
{ addCar(&fleet[i]);
strcpy(fleet[1+i].make,"SNT");
}
else printf("Fleet full, delete a car to add more\n");
}
else if(choice ==2) /*choice2*/
{
i=-1;
do{++i;}
while(strcmp(fleet[i].make, "SNT"));
if(i=0)
{ printf("No cars in Fleet to Delete");
}
else strcpy(fleet[i-1].make, "SNT");
}
else if(choice ==3) /*choice3*/
{showFleet(fleet);}
else if(choice ==4) /*choice4*/
saveFleet(fleet);
else if(choice ==5) /*choice5*/
readFleet(fleet);
else if(choice==6)
return(0);
}
/*END OF PROGRAM*/
void saveFleet(Car fleet[])
{
FILE* binaryp;
if((binaryp = fopen("fleet.bin", "wb")) == NULL)
printf("Cannot open fleet.bin for input");
else binaryp = fopen("fleet.bin", "wb");
fwrite(fleet, sizeof(Car), 10, binaryp);
fclose(binaryp);
printf("Fleet saved to file fleet.bin");
}
void readFleet(Car fleet[])
{
FILE* binaryp;
if((binaryp = fopen("fleet.bin", "rb"))== NULL)
printf("Cannot find fleet.bin to import filezzz");
else binaryp = fopen("fleet.bin", "rb");
fread(fleet, sizeof(Car),10,binaryp);
fclose(binaryp);
printf("Input of files complete");
}
void getDate(Date *dateimp)
{
printf("Year(YYYY)>");
scanf("%d", (*dateimp).year);
while((*dateimp).month<1||(*dateimp).month>12)
printf("Month(MM)>");
scanf("%d",(*dateimp).month);
if((*dateimp).month==1||(*dateimp).month==3||(*dateimp).month==5||(*dateimp).month==7||(*dateimp).month==8||(*dateimp).month==10||(*dateimp).month==12)
{while((*dateimp).day<1||(*dateimp).day>31)
printf("Day(From 1 to 31)>");
scanf("%d", (*dateimp).day);}
else if((*dateimp).month==9||(*dateimp).month==4||(*dateimp).month==7||(*dateimp).month==11)
{while((*dateimp).day<1||(*dateimp).day>30)
printf("Day(From 1 to 30)>");
scanf("%d", (*dateimp).day);}
else if((*dateimp).month==2)
{while((*dateimp).day<1||(*dateimp).day>29)
printf("Day(From 1 to 29)>");
scanf("%d", (*dateimp).day);
}
void addCar(Car* newcar)
{
printf("Input the cars' model>");
scanf("%s",(*newcar).make);
printf("Input the cars Purchase Date>");
getDate(&(*newcar).purchaseDate);
printf("Input the cars' manufacture date>");
getDate(&(*newcar).manufactureDate);
printf("Input Purchase Price>$");
scanf("%lf", &(*newcar).purchasePrice);
}
void showFleet(Car fleet[])
{
int p;
p=0;
while(strcmp(fleet[p].make, "SNT"))
{
showCar(&fleet[p]);
++p;}
if(p=0)
{printf("No cars in Fleet");}
}
void showDate(Date* sdate)
{ printf("%lf",(*sdate).day);
printf("/");
printf("%lf",(*sdate).month);
printf("/");
printf("%lf",(*sdate).year);}
}
void showCar(Car* shcar)
{ printf("Model Name %s",(*shcar).make);
printf("Manufacture Date:");
showDate(&(*shcar).manufactureDate);
printf("Purchase Date:");
showDate(&(*shcar).purchaseDate);
printf("Purcahse Price $%f\n",(*shcar).purchasePrice);
}
Cheers