hi everyone
i am trying to write a program for a library system that allow stuff to add, remove, view and delete customer. i try to use file to store data and i open the file in mode read then i store then i put the content of the file into a struture. now the problem started it is only showing me haft of the content and here is the coding. please help me
i am trying to write a program for a library system that allow stuff to add, remove, view and delete customer. i try to use file to store data and i open the file in mode read then i store then i put the content of the file into a struture. now the problem started it is only showing me haft of the content and here is the coding. please help me
Code:
#include <stdio.h>
# include <windows.h>
# include <stdlib.h>
#include<string.h>
#include<conio.h>
void search(int s,struct books eli[20]);
void view(int x,struct books eli[20]);
struct books{
char name[22], book[25],date1[10], date2[10],id[7],bid[7];
};
int main()
{
struct books eli[20];
int num,ctr=0,index=0;
FILE *fp;
fp = fopen("database.txt","r");
while(fscanf(fp,"%s %s %s %s %s %s", eli[ctr].name,eli[ctr].id,eli[ctr].book,eli[ctr].bid,eli[ctr].date1,eli[ctr].date2)!=EOF)
{
fscanf(fp,"%s %s %s %s %s %s", eli[ctr].name,eli[ctr].id,eli[ctr].book,eli[ctr].bid,eli[ctr].date1,eli[ctr].date2);
ctr=ctr+1;
index=ctr+index;
}
fclose(fp);
do
{
system("cls");
printf("\n\t\t***************************************");
printf("\n\t\t\t\t\t\t\t\t\t\t\t\t\t Welcome To BOOK MENU ");
printf("\n\t\t***************************************\n");
printf("\t\t1. Loan Transaction");
printf("\n\t\t2. Update");
printf("\n\t\t3. View Books");
printf("\n\t\t4. Exit");
printf("\n\t\t***************************************");
printf("\n\t\t Choice:");
scanf("%d", &num);
switch(num)
{
case 1:
search(index,eli);
break;
case 2:
view(index,eli);
break;
case 3:
return 0;
break;
default :
printf(" \n\t\t wrong value !!!");
break;
}
}while(num!=3);
Sleep(2000);
}
void view(int x,struct books eli[20])
{
printf("%d",x);
int ct;
for(ct=0;ct<x;ct++)
{
printf("\n%-13s %-13s %-13s %-13s %-13s %-13s",eli[ct].name,eli[ct].id,eli[ct].book,eli[ct].bid,eli[ct].date1,eli[ct].date2);
}
Sleep(5000);
}
void search(int s,struct books eli[20])
{
char name[20];
int ct=0;
printf("\n\t\t Username: ");
scanf("%s",name);
fflush(stdin);
for(ct=0;ct<s;ct++)
{
if(strcmp(name,eli[ct].name)==0)
{
printf("\n%-13s %-13s %-13s %-13s %-13s %-13s",eli[ct].name,eli[ct].id,eli[ct].book,eli[ct].bid,eli[ct].date1,eli[ct].date2);
break;
}else
printf("could not found");
}
Sleep(2000);
}
Comment