Thread: Help pls!(search)

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    14

    Help pls!(search)

    With this code i am searching a person who is saved in a struct in a TXT by his document number and then i print that person if actualy exist in the file. it works.
    What i want to do now is if i find more then one person with the same document number in the same file print it also.
    can some one help me i am not really that good in this.
    Ty.
    Code:
    Pnodo searchDocumentInPeople(Pnodo lista,int document)
    {
        Pnodo aux;
    
        for(aux = lista;aux!=NULL; aux = aux->sig)
        {
            if(aux->info.document==document)
            {
               return aux;//return the direction of the node where it was found
              }
        }
        return NULL;//is not threre

  2. #2
    Registered User
    Join Date
    Sep 2015
    Posts
    14
    Here is where i print the data but it just print the first one
    Code:
         printf("\nsearch Document In People\n");
                    printf("\nDocument: ");fflush(stdin);scanf("%d",&p.document);
    
                    ptr = searchDocumentInPeople(lista,p.document);
                    if(ptr==NULL)
                    {
                        printf("IT DO NOt EXIST!!!! ");
                    }
                    else
                    {
                        printf("%d,%s,%s,%d,%d\n",ptr->info.document,
                                           ptr->info.name,
                                           ptr->info.lastname,
                                           ptr->info.condicion,
                                           ptr->info.departament);
    
    
                    }

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Stop using fflush(stdin)
    FAQ > Why fflush(stdin) is wrong - Cprogramming.com

    In order to print out all the matching elements, you need a loop somewhere in your code.
    Code:
    ptr = lista;
    while ( (ptr = searchDocumentInPeople(ptr,p.document)) != NULL ) {
                   printf("%d,%s,%s,%d,%d\n",ptr->info.document,
                                      ptr->info.name,
                                      ptr->info.lastname,
                                      ptr->info.condicion,
                                      ptr->info.departament);
        ptr = ptr->sig;
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lyric search program - search function question
    By Jpaul8986 in forum C++ Programming
    Replies: 9
    Last Post: 07-28-2015, 11:56 AM
  2. Binary Search Tree-search method help?
    By shocklightning in forum C++ Programming
    Replies: 5
    Last Post: 03-25-2012, 10:57 PM
  3. Advanced Search -> Search Multiple Content Types
    By phantomotap in forum Tech Board
    Replies: 2
    Last Post: 05-21-2011, 07:28 AM
  4. Difference Between A Linear Search And Binary Search
    By ImBack92 in forum C Programming
    Replies: 4
    Last Post: 05-12-2011, 08:47 AM
  5. Allowing my search function to search sub directories!
    By Queatrix in forum Windows Programming
    Replies: 10
    Last Post: 09-30-2005, 04:54 PM

Tags for this Thread