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

It shows undefined reference because the functions showFleet, addcar are not "call by reference " functions.

When I add the Ampersand to the code as you have I get a syntax error.

oops sorry, I made a mistake. You cannot have reference to an array. So remove the &.
And also remove it in line 58 and also in lines 202, 204.

addCar(fleet[i]);

So the fleet[] in the main will not be modified by addcar() or any other function.

Sorry I still don't understand.

Do I just have to delete the &'s from line 58, 202, 204?

Yes, by doing so you won't get those errors.

I deleted the 3 &'s and I got this

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
gcc.exe -c finalmain2.c -o finalmain2.o -I"C:/Dev-Cpp/include"    -g

finalmain2.c: In function `main':
finalmain2.c:58: error: incompatible type for argument 1 of `addCar'

finalmain2.c: In function `showCar':
finalmain2.c:202: error: incompatible type for argument 1 of `showDate'

finalmain2.c:204: error: incompatible type for argument 1 of `showDate'

make.exe: *** [finalmain2.o] Error 1

Execution terminated

Nobody in they right mind should write 200+ lines of code before compiling the code. 10-20 lines is more like it with fixed data in code and simple printf instead fancy stuff. BTW (*variable_pointer).record is same as variable_pointer->record and generally thought to be more readable.

You must be sure that you have old functions working, then add one more thing to code and test again. For me 10 times the time of coding for debugging and testing looks about right.

A quick check on your code shows extra '}' between lines 196-197.
Hope that fixes it.

Sorry for the double post. getDate() is also missing a '}' at 160-161.
That last '}' at line 161 is intended for the else-if.

Try formatting your code well. It'll do you good to be neat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.