Search By Book Title.

This is a discussion on Search By Book Title. within the C Programming forums, part of the General Programming Boards category; Code: void search_title (BOOK book_array[]) { int search_database(); char book_name[SIZE]; int pos, i ; printf("Book Name to Display (max 20 ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    44

    Search By Book Title.

    Code:
    void search_title (BOOK book_array[])
    {
    int search_database();
    	
    char book_name[SIZE];
    int pos, i ;
    
    printf("Book Name to Display (max 20 chars) :");
    scanf( "%d",&book_name );
    
    /*HERE IS THE PROBLEM, I KNOW I CANT DO THIS HOW CAN I???*/
    
    while ( i < SIZE && book_array[i].name != book_name )
    	i++;
    
    pos =  i;
    
    if ( pos == SIZE )
    	printf( "This Book is not in the database\n" );
    else
    	{
    	printf("Number Of Book: %3d\n Name Of Book: %s\n Status Of Book: %c", book_array[pos].number, book_array[pos].name, book_array[pos].status);
    	fflush(stdin);
    	system("PAUSE");
    	}
    }
    Dangerous Dave

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    44
    in the while loop i am comparing a string with logic opperators, what else can i do?
    Dangerous Dave

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > /*HERE IS THE PROBLEM, I KNOW I CANT DO THIS HOW CAN I???*/
    > while ( i < SIZE && book_array[i].name != book_name )

    strcmp()

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    44
    Code:
    while ( i < SIZE && strcmp(book_array[i].name, book_name) != 0)
    		i++;

    should that do the trick?
    Dangerous Dave

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Right. Once it is zero, then you know you have a match for the name.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Unregistered
    Guest

    Angry

    This is Dave Carroll!!!! Stop your cogging!!!!!!!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exhaustive graph search
    By Cpro in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2008, 12:08 PM
  2. a phone book program
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-19-2007, 07:31 AM
  3. URGENT: Help wanted...in C
    By iamjimjohn in forum C Programming
    Replies: 16
    Last Post: 05-18-2007, 06:46 AM
  4. Question about book
    By Kaidao in forum C++ Programming
    Replies: 6
    Last Post: 03-20-2006, 03:31 AM
  5. Simple search program
    By colinuk in forum C Programming
    Replies: 6
    Last Post: 12-18-2004, 01:58 AM

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