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;

typedef struct{
        char make[10];
        Date manufactureDate;
        Date purchaseDate;
        double purchasePrice;
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("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>");
scanf("%d", &choice); 
else(printf("Input number must be from 1 to 6"));
scanf("%d", &choice);

if(choice == 1)         /*choice1*/
while(strcmp(fleet[i].make, "SNT"));
{       addCar(&fleet[i]);  
else printf("Fleet full, delete a car to add more\n");

else if(choice ==2)         /*choice2*/
while(strcmp(fleet[i].make, "SNT"));

{      printf("No cars in Fleet to Delete");
else strcpy(fleet[i-1].make, "SNT");     

else if(choice ==3)         /*choice3*/

else if(choice ==4)    /*choice4*/

else if(choice ==5)       /*choice5*/

else if(choice==6)

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);
              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);
              printf("Input of files complete");


void getDate(Date *dateimp)
    scanf("%d", (*dateimp).year);
    printf("Day(From 1 to 31)>");
    scanf("%d", (*dateimp).day);}
    else if((*dateimp).month==9||(*dateimp).month==4||(*dateimp).month==7||(*dateimp).month==11)
    printf("Day(From 1 to 30)>");
    scanf("%d", (*dateimp).day);}
    else if((*dateimp).month==2)
    printf("Day(From 1 to 29)>");
    scanf("%d", (*dateimp).day);

void addCar(Car* newcar)
    printf("Input the cars' model>");
    printf("Input the cars Purchase Date>");
    printf("Input the cars' manufacture date>");
    printf("Input Purchase Price>$");
    scanf("%lf", &(*newcar).purchasePrice);

void showFleet(Car fleet[])
     int p;
     while(strcmp(fleet[p].make, "SNT"))
    {printf("No cars in Fleet");}

 void showDate(Date* sdate)
{    printf("%lf",(*sdate).day);
void showCar(Car* shcar)
{    printf("Model Name %s",(*shcar).make);
     printf("Manufacture Date:");
     printf("Purchase Date:");
     printf("Purcahse Price $%f\n",(*shcar).purchasePrice);


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

Edited 5 Years Ago by Arbus: post had some mistakes

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.


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

Edited 5 Years Ago by Arbus: n/a

Sorry I still don't understand.

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

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.

Edited 5 Years Ago by pyTony: n/a

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.

Edited 5 Years Ago by yan0: n/a

This article has been dead for over six months. Start a new discussion instead.