Hi everybody .
i have a problem that i have been trying to solve for weeks can u help.
this is bonus problem given to me by my professor in college.
hers is the description:

menu driven library:
1. list books
2. add books
3. find books
a. by id
b. by title
4. delete books
a. by id
b. by title
5. modify books
6. exit

notes:
-read from file "books.txt"
-what we studied in C++ so far is(the basics+repetition+1&2-d array +strings)

this the books.txt file:

ID------Title------Author
1------C------Umar
2------C++------Naser
3------java------Ali
4------Fortran------Hossain
5------HTML------Muhammad
6------Flash------Khaled
7------Internet------Sami
8------Digital Signal------Umar
9------AI------Ibrahim
10------Assembly------Khaled
11------Math------Abdullah
12------Science ------Hossain
13------Engineering------Umar
14------ASP.NET------Naser
15------VB.NET------Asim
16------Linux------Muhammad
17------Unix------Khaled
18------Perl------Sami
19------Bioinformatics------Naser
20------Flash------Omar

(i put the dashes because i couldn't space them equally. in the file there equally spaced ,if that helps)

and this is what i manged to do this far:

#include <stdio.h>
#include <stdlib.h>
void list_book();
int main(int argc, char *argv[])
{
   int chos;
     
    
    printf("enter choice:\n");
  printf("1. list books.\n");
  printf("2. add books.\n");
  printf("3. find books\n");
  printf("4. delete books.\n");
  printf("5. modify books.\n");
  printf("6. exit.\n");
  printf(">");
  scanf("%d",&chos);
  
  switch(chos){
                case 1 : 
                
                list_book();
                 
                break;
                case 2 :printf("aaa\n");
                break;
                case 3 :
                break;
                case 4 :
                break;
                case 5 :
                break;
                case 6 :
                break;
                default: printf("unknown selction");}
                
  
  
  
  system("PAUSE");	
  return 0;
}



void list_book(){  
                FILE*book;
                int st;
                char  l;
                
                printf("\n------------------------------------\n");
                book=fopen("books.txt","r+");
                st=fscanf(book,"%c",&l);
                
                while(st!=EOF){
                printf("%c",l);
                st=fscanf(book,"%c",&l);
                }
                printf("\n\n");
                 fclose(book);
                 
                 }

and one last question is best to do it using array of string(like choice 3. and 4. from the menu ) or should i go another way?


please help any way you can and thank u.

Edited 6 Years Ago by aliyami90: n/a

You say "one last question" but I didn't see any questions before that? Also, what do you mean by choice 3 and 4? Please break you question into small parts and give them a shot. If you have a problem with a particular piece of code (maybe < 10 lines worth) we'll be happy to look at it.

Dave

VirtualAssist,

Welcome to DaniWeb! Thanks for posting a solution to this question! In the future, can you please be sure to use code tags around code? It makes it MUCH more readable for everyone.

Dave

@ VirtualAssit Its nice to see that you are trying to help but please use code tags. Secondly the code that you posted is non standard. void main() is a big no no. main should only return an int according to the c++ standard. The function clrscr() you used is also non standard and should not be used. goto is also another non c++ standard item. try using loops for program flow control. Why are you returning the head to the list you created when you end the program? main should return 0 on success and some other int like -1, 1 on failure. return something the OS isn't able to support or needs to pass to something else than cant handle it can cause problems. Lastly please don't spam links.

This article has been dead for over six months. Start a new discussion instead.