RSS Forums RSS
Please support our C advertiser: Programming Forums

i can't seem to make my search function work.... help!...

Join Date: Mar 2006
Posts: 1
Reputation: cinderella is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cinderella cinderella is offline Offline
Newbie Poster

i can't seem to make my search function work.... help!...

  #1  
Mar 28th, 2006
um... i'm an IT student. i'm still a freshmen though... i'm kinda confused with c programming. i have to make this program using stack. i can add, delete, and view all records but i can't seem to make my search function work. here's my codes, hopw anyone can help. thanks!

#include <stdio.h>

struct bookstore{

char title[15];
char author[15];
int booknum;
char publisher[15];
int quantity;
struct bookstore *end;
};

typedef struct bookstore *book;
book add, first, del,temp;

void insert(void);
void delete(void);
void viewall(void);
book search(void);

main()
{
int choice=0;
do
{
clrscr();
printf("Bookstore Data Entry System\n");
printf("\n[1] Add a Book");
printf("\n[2] Delete a Book");
printf("\n[3] Display Books from Stack");
printf("\n[4] Search");
printf("\n[5] Exit");
printf("\nChoice: ");
scanf("%d",&choice);

switch(choice){
case 1: insert(); break;
case 2: printf("\n\n\n\n");
printf("Latest Entry Deleted.");
delete();
break;
case 3: viewall(); break;
case 4: search(); break;
}
}while(choice != 5);
getch();

}

void insert(void)
{
add = (book)malloc(sizeof(struct bookstore)); fflush(stdin);
printf("\nBook Number: "); scanf("%d",&add->booknum); fflush(stdin);
printf("\nBook Title: "); gets(add->title); fflush(stdin);
printf("\nAuthor: "); gets(add->author); fflush(stdin);
printf("\nQuantity: "); scanf("%d",&add->quantity); fflush(stdin);
printf("\nPublisher: "); gets(add->publisher); fflush(stdin);
add->end = first;
first = add;
}

void delete(void)
{
del = first;
first = first->end;
free(del);
getch();
}

void viewall(void)
{
del = first;
printf("\nBookstore Data Entry System\n\n");
while(del)
{
printf("\nBook Number: %s",del->booknum);
printf("\nBook Title: %s",del->title);
printf("\nAuthor: %s",del->author);
printf("\nQuantity: %d",del->quantity);
printf("\nPublisher: %s",del->publisher);
printf("\n\n");
del = del->end;
}
printf("\n\n");
system("PAUSE");
}

book search(void)
{
int i;
printf("\n\nEnter book number to be SEARCHED: ");
scanf("%d",&i);
booknum = &i;
temp = first;
while(temp != NULL)
{
if(temp->booknum == i)
printf("\nNo record");
else
temp = temp->bookstore;
++i;
}
printf("\nBook Number: %s",del->booknum);
printf("\nBook Title: %s",del->title);
printf("\nAuthor: %s",del->author);
printf("\nQuantity: %d",del->quantity);
printf("\nPublisher: %s",del->publisher);
printf("\n\n");

}


AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:29 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC