Basicly i tried to do address book but i guest it not work at all..can i know where i get wrong or any advise?..

The problem is a faulty flux capacitor on line 42.

hi narue..this is my program for address book..could you help me?i cant compile it due to [linker error]undefined reference to contactlistrecord..plz..plzz..plz

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<conio.h>

/*prototypes*/
void initializeFile(FILE*);
void inputData(FILE *);
int instructions(void);
void contactListRecord(FILE*);
void editContactRecord(FILE*);
void addContactRecord(FILE*);
void deleteContactRecord(FILE*);

/*structure definition*/
struct addressData {
     int partnumber;   
     char contactname[40]; 
     int phonenumber;
     char email;          
     char address;   
   };/*end structure definition*/

main()
{
   FILE *filePtr; /*file pointer*/
   char response[2];
   int process;

   printf("Should the file be initialized?(Y or N):");
   scanf("%s",&response);

	/*process user's choice*/
   while (toupper(response[0]) !='Y' && toupper(response[0]) !='N') 
   {
      printf("Invalid response.Enter Y or N:");
      scanf("%s",&response);
   }

   if (toupper(response[0]) == 'Y')
   {
      if ((filePtr=fopen("address.dat","w")) == NULL)
	  {
	 printf("File could not be opened.\n");
	 getche();
	 exit(1);
      }
      initializeFile(filePtr);
      inputData(filePtr);
      fclose(filePtr);
   }

   if((filePtr=fopen("address.dat","r+")) == NULL) 
   {
      printf("File could not be opened.\n");
      getche();
      exit(1);
   }
	/* enable user to specify action*/
   while ((process = instructions()) != 5) 
   {
      switch (process) 
	  {
	
	 case 1:
	    contactListRecord(filePtr);
	    break;
	
	 case 2:
	    editContactRecord(filePtr);
	    break;
	
	 case 3:
	    addContactRecord(filePtr);
	    break;
	
	 case 4:
	    deleteContactRecord(filePtr);
	    break;
     }/*end switch*/
   }/*end while*/

   fclose(filePtr); /*fclose closes the file*/
   getche();
   return 0; /*indicates successful termination*/
}/*end main*/

void initializeFile(FILE *fPtr)
{
   struct addressData blankItem = {0, "", 0, 0.0};
   int i;

   for (i = 0; i<= 99; i++)
      fwrite(&blankItem, sizeof(struct addressData), 1, fPtr);
}
/*create formatted input data*/
void inputData(FILE *fPtr)
{
   struct addressData temp;
   
   printf("\nEnter the partnumber (0 - 99, -1 to end input):");
   scanf("%d", &temp.partnumber);

   while (temp.partnumber != -1) {
      printf("Enter your name,email,address and phonenumber:\n");
      scanf(" %c\n %c\n%c\n%d", &temp.contactname, &temp.email, &temp.phonenumber);
      fseek(fPtr, temp.partnumber * sizeof(struct addressData), SEEK_SET);
      fwrite(&temp, sizeof(struct addressData), 1, fPtr);

      printf("\nEnter the partNumber (0 - 99, -1 to end input):");
      scanf("%d", &temp.partnumber);
   }
}

int instructions(void)
{
   int choice;

   printf("\n%s\n%s\n%s\n%s\n%s\n%s\n? ", "Enter a choice:",
	  "1 - List all contact.", "2 - edit contact.", "3 - add contact.",
	  "4 - Delete record.", "5 - End program.");
   scanf("%d", &choice);

   while (choice < 1 || choice > 5) 
   {
      printf("Invalid choice.Enter a choice again: ");
      scanf("%d", &choice);

   }

   return choice;
}

void contactlistRecord(FILE *fPtr)
{
   struct addressData temp;

   fseek(fPtr, sizeof(struct addressData), SEEK_SET);
   printf("\n%-8s%-30s%-8s%8s%8s\n", "Record #", " name", "phone number", "email", "address");
   while (!feof(fPtr)) 
   {
      fread(&temp, sizeof(struct addressData), 1, fPtr);

      if (temp.partnumber)
	 printf("%-9s%-29s%8d%8s%8s\n", temp.partnumber, temp.contactname, temp.phonenumber,
    	temp.email, temp.address);
   }
}

void editcontactRecord(FILE *fPtr)
{
   
   struct addressData temp;
   int part;

   
   printf("\nEnter the partnumber for update:");
   scanf("%d", &part);
   
   fseek(fPtr, part * sizeof(struct addressData), SEEK_SET);
   
   fread(&temp, sizeof(struct addressData), 1, fPtr);

   if(temp.partnumber) 
   {
     printf("\n%-8s%-30s%-8s-%8s\n","Record #", " name", "phone number", "email", "address");
     printf("%-8d %-29s%8d%8s%d\n", temp.partnumber, temp.contactname,
     	temp.phonenumber, temp.email, temp.address);
     printf("\nEnter the name, phone number, email and address:\n");
     scanf(" %-8s%-30d%-8s-%8s", &temp.contactname, &temp.phonenumber, &temp.email, temp.address);
     fseek(fPtr, temp.partnumber * sizeof(struct addressData), SEEK_SET);
     fwrite(&temp, sizeof(struct addressData), 1, fPtr);
   }

   else
     printf("Cannot edit.The record is empty.\n");
}


void addcontactRecord(FILE *fPtr)
{
	
   struct addressData temp;
   int part; /*partnumber*/
   /*obtain partnumber to create*/
   printf("\nEnter the partnumber for insertion:");
   scanf("%d", &part);
   
   fseek(fPtr, part * sizeof(struct addressData), SEEK_SET);
   
   fread(&temp, sizeof(struct addressData), 1, fPtr);
   
   /*display error if partnumber is already exists*/
   if(!temp.partnumber) 
   {
      temp.partnumber = part;
      printf("Enter the name, phone number, email and address:\n");
      scanf(" %-8s%-30d%-8s-%8s", &temp.contactname, &temp.phonenumber, &temp.email, &temp.address);
      fseek(fPtr, temp.partnumber * sizeof(struct addressData), SEEK_SET);
      fwrite(&temp, sizeof(struct addressData), 1, fPtr);
   } /*end if*/

   else 
      printf("Cannot insert.The record contains information.\n");
} /*end else*/


void deletecontactRecord(FILE *fPtr)
{
   struct addressData blankItem = {0, "", 0, 0.0}, temp; /*blankitem*/
   int part; /*partnumber*/

   /*obtain partnumber to delete*/
   printf("\nEnter the partnumber for deletion:");
   scanf("%d", &part);
   
   fseek(fPtr, part * sizeof(struct addressData), SEEK_SET);
   
   fread(&temp, sizeof(struct addressData), 1, fPtr);

   if (temp.partnumber) 
   {
      fseek(fPtr, part * sizeof(struct addressData), SEEK_SET);
      fwrite(&blankItem, sizeof(struct addressData), 1, fPtr);
      printf("Record deleted.\n");
   } /*end if*/

   else
      printf("Cannot delete.The record is empty.\n");

} /*end main*/

C is case-sensitive. The name you use in the function definition must match the name in the prototype exactly. Spelling, capitalization, everything. I usually just copy and paste; it's easier to get right every time that way.

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.