hi I'm having a problem with my addressbook recognizing the data I've inputted into it (displaying and deleting) It stores the data into a txt file and should use that file to pick up any similarities when the user inputs a similar name. So far it compiles and displays options and I can input entries but when I try searching for the very same entries...no luck...I look up the txt file and it has the entry i inputted in that very file...Can someone please help me I have a week left and I'm hoping I can get this code to work.

#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define NAME 30
#define ADDRESS 80
#define PHONE 11
#define EMAIL 50
#define SIZE 500
void Insert();
void Deleteinfo();
void Search();
void Exit();
char info[SIZE];
struct addressbook
{
  char name [NAME];
  char address [ADDRESS];
  char phone [PHONE];
  char email [EMAIL];
  char Target[NAME];
} myaddressbook;

FILE *AddressBook;
FILE *rectemp;
int main()
{  
  int choice=0;
  printf("Welcome \n");
    printf("\n 1> Insert new Entry\n");
    printf("\n 2> Delete Entry\n");
    printf("\n 3> Search Entry\n");
    printf("\n 4> Exit the program\n");
    printf("\n Enter your choice <1-4>: ");
    scanf("%i",&choice);
    if(choice == 1){
    Insert();
    return main();
    }
    else if(choice ==2){
    Deleteinfo();
    return main();
    }
    else if(choice ==3){
    Search();
    return main();
 }
    else if(choice ==4){
    printf("Exit program \n");
 Exit();
    }
    }
void Insert()
{
  char choice1;
  do
  {  //opening the AddressBook file
    AddressBook = fopen("AddressBook.txt","a+");
    printf("Enter Person's Name\n");
    scanf("%s",myaddressbook.name);
	
    printf("Enter Person's Address\n");
    scanf("%s",myaddressbook.address);
    
	printf("Enter Person's Phone no.\n");
    scanf("%s",myaddressbook.phone);
    
	printf("Enter Person's E-mail\n");
    scanf("%s",myaddressbook.email);
    
	fprintf(AddressBook,"%s %s %s %s  \n",myaddressbook.name,myaddressbook.address,myaddressbook.phone,myaddressbook.email);
    fclose(AddressBook);
    printf("Press y/Y to Execute the Program Again \n");
    scanf("%c",&choice1);
  }
  while(choice1=='y'||choice1=='Y');
  main();
}
void Deleteinfo()
{
  char choice2;
  char Target[SIZE];
  int Found=0;
  rectemp=fopen("rectemp.txt","w");
  if((AddressBook=fopen("AddressBook.txt","r"))==NULL)
    printf("**The File is Empty**\n\n");
  else{
    printf("\tEnter Person's Name : ");
    while(!(AddressBook))
    {
      fscanf(AddressBook,"%s %s %s %s",myaddressbook.name,myaddressbook.address,myaddressbook.phone,myaddressbook.email);
      if(feof(AddressBook))
        break;
      if(strcmp(Target,myaddressbook.name)!=0)
        fprintf(rectemp,"%s %s %s %s \n",myaddressbook.name,myaddressbook.address,myaddressbook.phone,myaddressbook.email);
      else {
        Found=1;
      }
      if (!Found)
      {
        printf("\t**There is no such Entry\n");
      }
      printf("\t**Item is Deleted**\n");
      fclose(AddressBook);
      fclose(rectemp);
      remove("AddressBook.txt");
      rename("rectemp.txt","AddressBook.txt");
    }
	main();
    }
  }

void Search()
{
  char choice4; 
  char Target[SIZE];
  int Found=0;
  if((AddressBook=fopen("AddressBook.txt","r"))==NULL)
    printf("**The file is empty** !!\n\n");
  else
  {
    printf("\tEnter The Name:");
    scanf("%s",Target);
    while(!(AddressBook)&& Found==0)
    {
      fscanf(AddressBook,"%s %s %s %s ",myaddressbook.name,myaddressbook.address,myaddressbook.phone,myaddressbook.email);
      if(strcmp(Target,myaddressbook.name)==0)
        Found=1;
    }
    if(Found)
    {
      printf("The Name is:               %s\n",myaddressbook.name);
      printf("The Address is:            %s\n",myaddressbook.address);
      printf("The phone number is:       %s\n",myaddressbook.phone);
      printf("The e-mail is:             %s\n",myaddressbook.email);
    }
    else if(!Found)
      printf("**There is no such Entry**\n");
    fclose(AddressBook);
  }
  main();
}

void Exit()
{
  exit(0);
}

look VERY carefully at Target and myaddressbook.name, and you'll see (I believe), one of them has a newline that the other doesn't have. That's what's tripping up strcmp(), and your search.

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.