O! Główne forum pokazuje mi zero odpowiedzi, dlatego jeszcze nic nie dzialam, moj blad. Jest to minimum ktore sie kompiluje, takze mozna wrzucic do kompilatora.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int main()
{
int a=0,b=0,e=0,h=0,i=0,j=0,x=0;
int hm,nb;
char c,d;
FILE *p;
p=fopen("test.txt","a+b");
struct store
{
char title[100];
char author[50];
char genre[25];
char year[10];
char pages[10];
char price[10];
int howmany;
char tmp[5];
};
store base[50];
for(i=0;i<50;i++)
{
strcpy(base[i].title,"(null)");
strcpy(base[i].author,"(null)");
strcpy(base[i].genre,"(null)");
strcpy(base[i].year,"(null)");
strcpy(base[i].pages,"(null)");
strcpy(base[i].price,"(null)");
base[i].howmany=0;
}
fread(base,sizeof(store),50,p);
do
{
printf("\tMENU\n");
printf("\t1. Quick add book.\n"); /*READY*/
printf("\t4. Inventory.\n");
printf("\t5. Exit.\n"); /*READY*/
char tmp[100];
fgets(tmp,100,stdin);
sscanf(tmp,"%c",&c);
switch(c)
{
case '1': /*adds just one book - DONE*/
hm=0;
system("cls");
while(strcmp(base[e].title,"(null)")!=0)
{
e++;
if(e==50)
break;
}
if(strcmp(base[e].title,"(null)")==0)
{
printf("What is the title of the book?\n");
fgets(base[e].title,sizeof(base[e].title),stdin);
for(j=0;j<50;j++)
for(x=0;x<50;x++)
if(x!=j && strcmp(base[x].title,base[j].title)==0)
{
if(strcmp(base[x].title,"(null)")==0)
break;
else if(strcmp(base[j].title,"(null)")==0)
break;
else
{
printf("This book is already in our data base! Press ENTER to continue.\n");
getchar();
strcpy(base[e].title,"(null)");
base[j].howmany=base[j].howmany+1;
hm=1;
system("cls");
break;
}
}
else
{
}
if(hm==0)
{
printf("What is the author of the book?\n");
fgets(base[e].author,sizeof(base[e].author),stdin);
printf("What kind of genre is that?\n");
fgets(base[e].genre,sizeof(base[e].genre),stdin);
printf("What year the book was released?\n");
fgets(base[e].year,sizeof(base[e].year),stdin);
printf("How many pages does the book count?\n");
fgets(base[e].pages,sizeof(base[e].pages),stdin);
printf("What is the price?\n");
fgets(base[e].price,sizeof(base[e].price),stdin);
base[e].howmany=1;
printf("Book(s) added succesfully! Press ENTER to return to the menu.\n");
}
else
break;
}
else
{
printf("Our database is full! Press ENTER to continue.\n");
getchar();
system("cls");
}
getchar();
system("cls");
break;
case '4': /*inventory*/
system("cls");
for(b=0;b<10;b++)
printf("Title: %sAuthor: %sGenre: %sYear: %sPages: %sPrice: %sQuantity:%d\n\n",base[b].title,base[b].author,base[b].genre,base[b].year,base[b].pages,base[b].price,base[b].howmany);
break;
case '5':
system("cls");
printf("Thank You! Press ENTER to leave");
getchar();
break;
default:
system("cls");
printf("Error, press any key to back to the main menu");
getchar();
system("cls");
}
}while(c!='5');
fwrite(base,sizeof(store),50,p);
fclose(p);
}