zanydude

This is a discussion on zanydude within the C Programming forums, part of the General Programming Boards category; i've got problem in searching plz help me aout. this is telephone directory program. coding: Code: #include<stdio.h> #include<conio.h> void info(void); ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    2

    zanydude

    i've got problem in searching plz help me aout.
    this is telephone directory program.

    coding:
    Code:
    #include<stdio.h>
    #include<conio.h>
    void info(void);
    void search(void);
    struct TD
    {
      char name[20];
      char add[40];
      char ph[10];
      char email[20];
    
    };
      struct TD ppl[50];
      int n=0;
    
    void main(void)
    {
      char ch;
      clrscr();
      printf ("\t\tTELEPHONE DIRECTORY\n\n");
      while (1)
       {
    
         printf ("\n\nType 'e' for entering the new information\n");
         printf ("Type 's' for search\n");
         printf ("Type 'q' for quit");
         ch=getche();
         switch(ch)
           {
    	  case 'e':
    	  info();
    	  break;
    
    	  case 's':
    	  search();
    	  break;
    
    	  case 'q':
    	  exit(0);
    
    	  default:
    	  printf ("Enter only the selection listed");
    	}
         }
     }
    
    void info(void)
     {
       clrscr();
       printf ("\nRecord #%d:\nEnter the name:",n+1);
       gets (ppl[n].name);
       printf ("Enter the address:");
       gets (ppl[n].add);
       printf ("Enter the telephone #:");
       gets (ppl[n].ph);
       printf ("Enter the email:");
       gets (ppl[n++].email);
     }
    
    
    void search(void)
    {
      int j,k,position;
      char name1[20];
      clrscr();
      if (n<1)
      printf ("Empty list\n");
      else
      printf ("\n\nEnter the name for information:");
      gets(name1);
    
      for ( j=0 ; j<n ; j++)
    	if ( name1 == ppl[j].name)
    	   {
    	      printf ("\nName: %s",ppl[j].name);
    	      printf ("\nAddress: %s",ppl[j].add);
    	      printf ("\nPhone #: %s",ppl[j].ph);
    	      printf ("\nE-mail: %s",ppl[j].email);
    	    }
    	 else
    	     printf ("\nRecord not found");
    
     }



    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    Read This First

    >>i've got problem in searching plz help me aout.
    You've got several problems, the main one being a lack of code tags, edit your post with code tags and can you be more specific with your question.

    >>if ( name1 == ppl[j].name)
    for a start you cant compare strings like this you need to use strcmp.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >void main(void)
    main returns an int, nothing else.

    >exit(0);
    This is undefined since you don't include stdlib.h.

    >if ( name1 == ppl[j].name)
    This should be

    if ( strcmp ( name1, ppl[j].name ) == 0 )

    and you need to include string.h as well.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21