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.