5 Replies - 1144 Views - Last Post: 20 March 2011 - 11:18 AM Rate Topic: -----

#1 status90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 24-September 09

Linker Error

Posted 20 March 2011 - 08:24 AM

There are 4 Errors:

Quote

Linker Error: _vehicle defined in module ADDVEH.C is duplicated in module RUN.C
Linker Error: _vehicle defined in module ADDVEH.C is duplicated in module TAXREP.C
Linker Error: _vehicle defined in module ADDVEH.C is duplicated in module VEHENQ.C
Linker Error: Undefined symbol _initiald in module RUN.C


All these are linking to SE.EXE where it's a project to compile all the functions in 1 go.

FYI, I'm using Turbo C++ IDE. And I'm quite new in C++ (around 2 months or less). Since I'm new, I did tried any possible answers to fixed them from search engines, however I just couldn't find or understand a specific fix for it.

Below are the coding that have errors as above stated:
RUN.C
#include <stdio.h>

struct vehicledata{
		   int vehnum;
		   char regisnum[7];
		   char make[15];
		   char model[15];
		   char engtype[2];
		   int cc;
		   char rmonth[4];
		   char ryear[5];
		   } vehicle = {0,"","","","",0,"",""};

int val_choice( void );
void addveh( FILE * );
void vehenq( FILE * );
void taxrep( FILE * );
void initiald( FILE * );

int main()
{

   FILE *cfptr;
   int option;

   if ( ( cfptr = fopen( "vehicle.db", "r+" ) ) == NULL )
      printf( "File could not be opened.\n" );
   else { 

      while ( ( option = show_menu() ) != 5 ) { 

         switch ( option ) { 
            case 1:
               addveh( cfptr );
               break;
            case 2:
               vehenq( cfptr );
               break;
            case 3:
               taxrep( cfptr );
               break;
            case 4:
               initiald( cfptr );
               break;
         }
      }

      fclose( cfptr );
   }

   return 0;
}

ADDVEH.C
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

struct vehicledata{
		   int vehnum;
		   char regisnum[7];
		   char make[15];
		   char model[15];
		   char engtype[2];
		   int cc;
		   char rmonth[4];
		   char ryear[5];
		   } vehicle = {0,"","","","",0,"",""};

void addveh( FILE *fptr )
{

 char response = 'Y';

 if (vehicle.vehnum != 0)
      printf ("Vehicle #%d already contains information.\n", vehicle.vehnum);
 else
   while(response != 'N')
	 {
	  clrscr();
	  gotoxy(13,1);
	  printf("===========================================================");
	  gotoxy(13,6);
	  printf("===========================================================");
	  gotoxy(30,3);
	  textcolor(BLUE);
	  printf("ADD VEHICLE SCREEN");

	  gotoxy(13,8);
	  printf("Vehicle Number: ");
	  scanf("%d", &vehicle.vehnum);

	  fflush(stdin);
	  gotoxy(13,10);
	  printf("Enter Reg. No: ");
	  add_regisnum();

	  fflush(stdin);
	  gotoxy(13,12);
	  printf("Enter Make: ");
	  add_make();

	  fflush(stdin);
	  gotoxy(13,14);
	  printf("Enter Model: ");
	  add_model();

	  fflush(stdin);
	  gotoxy(13,16);
	  printf("Engine Type (D or P): ");
	  add_engtype();

	  fflush(stdin);
	  gotoxy(13,18);
	  printf("Engine Capacity: ");
	  add_cc();

	  fflush(stdin);
	  gotoxy(13,20);
	  printf("Road tax expiry month (eg. sep): ");
	  gets(vehicle.rmonth);

	  fflush(stdin);
	  gotoxy(13,22);
	  printf("Road tax expiry year (eg. 2009): ");
	  gets(vehicle.ryear);

	  fseek(fptr, (vehicle.vehnum)*sizeof(struct vehicledata), SEEK_SET);
	  fwrite(&vehicle, sizeof(struct vehicledata), 1, fptr);

	  gotoxy(15,24);
	  printf("Do you want to add another record? (Y/N): ");
	  response = toupper(getchar());
	  flushall();

	 }

 fclose(fptr);

}

add_regisnum()
{
   int err=1, k;

   while (err == 1)        /* begin while for error is equal to one */
   {
      start:
      err=0;
      gotoxy(28,10);
      gets(vehicle.regisnum);

      k=0;
      while (vehicle.regisnum[k] != '\0')
      {
	    if (isdigit(vehicle.regisnum[k]))   /* check regis num is entered in numbers */
	      {
		gotoxy(13,11);
		printf("Registration number must be in character, please re-enter!"); /* display error msg */
		getch();
		err=1;
		gotoxy(13,11);
		printf("                                                            ");
		gotoxy(28,10);
		printf("                                                            ");
		goto start;

	      }

      k=0;
      while (vehicle.regisnum[k] != '\0') /* begin while regis num is not end of char */
      {
	    if (ispunct(vehicle.regisnum[k])) /* check regis num is entered in unusual characters */
		{
	       gotoxy(13,11);
	       printf("Invalid, please re-enter! "); /* display error msg */
	       getch();
	       err=1;
	       gotoxy(13,11);
	       printf("                                                                       ");
	       gotoxy(28,10);
	       printf("                                          ");
	       goto start;
	    }
	    else
	       ++k;                   /* increment k to check next character */
      }
      }                           /*endwhile*/
}

   return 0;
}


add_make()
{

   int err=1, k;
   while (err == 1)
   {
      start:
      err=0;
      gotoxy (25,12);
      gets(vehicle.make);

      k=0;
      while (vehicle.make[k] != '\0')
      {
	 if (isdigit(vehicle.make[k]))
	   {
	     gotoxy(13,13);
	     printf("Make must be in character, please re-enter: ");
	     getch();
	     err=1;
	     gotoxy(13,13);
	     printf ("                                                   ");
	     gotoxy(25,12);
	     printf ("                                                   ");
	     goto start;
	     }

      k=0;
      while (vehicle.make[k] != '\0')
      {
	 if (ispunct(vehicle.make[k]))
	 {
	 gotoxy(13,13);
	 printf ("Invalid, please re-enter: ");
	 getch();
	 err=1;
	 gotoxy(13,13);
	 printf ("                                         ");
	 gotoxy(25,12);
	 printf ("                                         ");

	 goto start;
	 }
	 else
	 ++k;
      }
   }
}
return 0;
}

add_model()
{

   int err=1, k;
   while (err == 1)
   {
      start:
      err=0;
      gotoxy (26,14);
      gets(vehicle.model);

      k=0;
      while (vehicle.model[k] != '\0')
      {
	 if (isdigit(vehicle.model[k]))
	   {
	     gotoxy(13,15);
	     printf("Make must be in character, please re-enter: ");
	     getch();
	     err=1;
	     gotoxy(13,15);
	     printf ("                                                   ");
	     gotoxy(26,14);
	     printf ("                                                   ");
	     goto start;
	     }

      k=0;
      while (vehicle.model[k] != '\0')
      {
	 if (ispunct(vehicle.model[k]))
	 {
	 gotoxy(13,15);
	 printf ("Invalid, please re-enter: ");
	 getch();
	 err=1;
	 gotoxy(13,15);
	 printf ("                                           ");
	 gotoxy(26,14);
	 printf ("                                           ");

	 goto start;
	 }
	 else
	 ++k;
      }

   }
}
return 0;
}

add_engtype()
{

	int err=1, k;
	while (err == 1)
	{

		start:
		err=0;
		gotoxy (35,16);
		gets(vehicle.engtype);

		 if (strcmp(vehicle.engtype, "D") !=0)
		   if (strcmp(vehicle.engtype, "P") !=0)

		{

		  gotoxy(13,17);
		  printf("Please enter either D for Diesel or P for Petrol: ");
		  getch();
		  err=1;
		  gotoxy(13,17);
		  printf ("                                                     ");
		  gotoxy(35,16);
		  printf("                                                      ");
		  goto start;
		}
	}
return 0;

}

add_cc()
{
   int err=1,k;

   while (err==1)
   {
      start:
      err=0;
      gotoxy(30,18);
      scanf("%d", &vehicle.cc);

      if ((vehicle.cc)>=10000)
      {
	gotoxy(13,19);
	printf ("Invalid! Please re-enter cc: ");
	getch();
	err=1;
	gotoxy(13,19);
	printf ("                                     ");
	gotoxy (30,18);
	printf ("                                     ");
	goto start;
       }
     }
     return 0;
}

TAXREP.C
#include <stdio.h>
#include<conio.h>
#include<time.h>
#include<string.h>

struct vehicledata{
		   int vehnum;
		   char regisnum[7];
		   char make[15];
		   char model[15];
		   char engtype[2];
		   int cc;
		   char rmonth[4];
		   char ryear[5];
		   } vehicle = {0,"","","","",0,"",""};
 
void taxrep( FILE * fptr )
{

   long rdate;
   char rcurrent[25];
   char currmonth[3];
   char curryear[4];

   int i=0, vec=0;
   float roadtaxAmt, totRoadTax=0;

   int r, nowmonth, nowyear;
   clrscr();
   time(&rdate);
   strcpy(rcurrent,&ctime(&rdate)[0]);


   /* Copy array elements for month */
   for(r=4;r<=6;r++){
      currmonth[r-4]=rcurrent[r];
   }
   /* Copy array elements for year */
   for(r=20;r<=23;r++){
      curryear[r-20]=rcurrent[r];
   }
   /* Header */
   printf("\n  ==========================================================================\n\n");
   printf("                      RENEWAL REPORT FOR THE MONTH\n\n");
   /* Display current system time */
   printf("                        %s\n", rcurrent);
   printf("  ==========================================================================\n");
   printf("  VEH REGSTR  MAKE           MODEL      ENG ENG    ROADTAX   ROADTAX\n");
   printf("  ID  NO                                TYP CC     EXPIRY    PAYMENT\n");
   printf("  ==========================================================================\n\n");
   if (vehicle.vehnum != 0)
      printf ("Vehicle #%d already contains information.\n", vehicle.vehnum);
   else
      while (!feof(fptr))
	      {
		 i++;
		 fseek(fptr, i*sizeof(struct vehicledata), SEEK_SET);
		 fread(&vehicle, sizeof(struct vehicledata), 1, fptr);

			 /*Displays data with expired roadtax*/
			 if((nowmonth==0)&&(nowyear==0)){
			    vec++;
			    roadtaxAmt = (2.25*vehicle.cc)/100;
			    printf("  %-4d%-8s%-15s%-12s%-3s%-6d%-4s%-6s $%.2f\n", vehicle.vehnum, vehicle.regisnum, vehicle.make,
					vehicle.model, vehicle.engtype, vehicle.cc, vehicle.rmonth, vehicle.ryear, roadtaxAmt);
			    totRoadTax=totRoadTax+roadtaxAmt;
			 }

	      }
	  /* Footer*/
	  printf("\n  ==========================================================================\n");
	  printf("   Number of Vehicles: %d. \n   Total Roadtax Payment: $%.2f\n", vec, totRoadTax);
	  printf("  ==========================================================================\n\n");
      printf("\n\n   Press any key to continue...");

      getch();

      fclose(fptr);

}

VEHENQ
/***** reading a random access file *****/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>

struct vehicledata{
		   int vehnum;
		   char regisnum[7];
		   char make[15];
		   char model[15];
		   char engtype[2];
		   int cc;
		   char rmonth[4];
		   char ryear[5];
		   } vehicle = {0,"","","","",0,"",""};

void vehenq( FILE *fptr )
{

 int vehnum;
 float roadtaxamt;
 char response = 'Y';

 if (vehicle.vehnum != 0)
      printf ("Vehicle #%d already contains information.\n", vehicle.vehnum);
 else
   response = 'Y';
   while (response != 'N')
	  {
	   clrscr();

	   gotoxy(25,3);
	   printf("Enter Vehicle Number: ");
	   scanf("%d", &vehnum);

	   fseek(fptr, vehnum*sizeof(struct vehicledata), SEEK_SET);
	   fread(&vehicle, sizeof(struct vehicledata), 1, fptr);          /*****reading from the database file*****/
	   fflush(stdin);

	   gotoxy(25,6);
	   printf("Registration Number: %s", vehicle.regisnum);
	   gotoxy(25,8);
	   printf("Make: %s", vehicle.make);
	   gotoxy(25,10);
	   printf("Model: %s", vehicle.model);
	   gotoxy(25,12);
	   printf("Engine Type: %s", vehicle.engtype);
	   gotoxy(25,14);
	   printf("Engine Capacity: %d", vehicle.cc);
	   gotoxy(25,16);
	   printf("Expired Date: %s", vehicle.rmonth);
	   gotoxy(43,16);
		fflush(stdin);
		gotoxy(44,16);
		printf("%s\n", vehicle.ryear);

	   gotoxy(25,18);
	   roadtaxamt = (2.25*vehicle.cc)/100;
	   printf("Road Tax Amount: $%.2f", roadtaxamt);
	   fflush(stdin);

	   gotoxy(25,22);
	   printf("Do you want to continue? (Y/N): ");
	   response = toupper(getchar());
	  }
   fclose(fptr);

}

INITIALD.C
/*****Creating and initialising a random file with 20 blank records *****/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

struct vehicledata{
		   int vehnum;
		   char regisnum[7];
		   char make[15];
		   char model[15];
		   char engtype[2];
		   int cc;
		   char rmonth[4];
		   char ryear[5];
		   } vehicle = {0,"","","","",0,"",""};

void initiald( FILE *fptr )
{

   FILE *cfptr;
   int i;

   if((cfptr = fopen("vehicle.db","w")) ==NULL) /*****Open vehicle.db for writing only *****/
      printf("File could not be opened.\n");
   else
      {
      clrscr();
      /***** Write 20 blank recods into credit.dat *****/
      for (i=1; i<=20;i++)
	fwrite(&vehicle, sizeof(struct vehicledata),1,fptr);

	  window(21,21,50,22);
	  textbackground(MAGENTA);
	  clrscr();
	  printf("DATABASE had been initialise!");
	  getch();

      fclose(cfptr);
      }
}


Since I'm new with C++, I hope for a detail explanation and if possible with the fix coding of it. I anticipate for the reply. :)

Is This A Good Question/Topic? 0
  • +

Replies To: Linker Error

#2 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Linker Error

Posted 20 March 2011 - 08:56 AM

/*****Creating and initialising a random file with 20 blank records *****/
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

struct vehicledata{
		   int vehnum;
		   char regisnum[7];
		   char make[15];
		   char model[15];
		   char engtype[2];
		   int cc;
		   char rmonth[4];
		   char ryear[5];
		   } vehicle = {0,"","","","",0,"",""};

}



It is most likely complaining that you are creating this in every one of your files.
Why don't you just create the struct once?
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Linker Error

Posted 20 March 2011 - 09:10 AM

Quote

FYI, I'm using Turbo C++ IDE. And I'm quite new in C++ (around 2 months or less). Since I'm new, I did tried any possible answers to fixed them from search engines, however I just couldn't find or understand a specific fix for it.


WHY, WHY, WHY, WHY, WHYYYY???? You're using 20+ year old technology!
Was This Post Helpful? 0
  • +
  • -

#4 status90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 24-September 09

Re: Linker Error

Posted 20 March 2011 - 09:19 AM

sk1v3r

Quote

It is most likely complaining that you are creating this in every one of your files.
Why don't you just create the struct once?

when i create the struct, there is undefined structured/symbols errors

JackOfAllTrades

Quote

WHY, WHY, WHY, WHY, WHYYYY???? You're using 20+ year old technology!

beats me, i'm just using it as required in my module...to familiarised us with old technology :/

This post has been edited by status90: 20 March 2011 - 09:20 AM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Linker Error

Posted 20 March 2011 - 11:16 AM

Yeah, that's it...to familiarize you to old technology. You're being lied to and cheated.
Was This Post Helpful? 1
  • +
  • -

#6 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: Linker Error

Posted 20 March 2011 - 11:18 AM

Indeed. With that said, put the struct in a header for all of your files to include.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1