Proszę o sprawdzenie tego kodu. Jak uruchamiam program to wyświetla mi przez moment okienko cmd i wyłącza się.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
struct book {
char title[50];
char genre[50];
char aname[50];
int year;
};
void typing(struct book library[10])
{
int c=1;
int i=0;
for (i=0; i<10; i++)
{
//char line[255];
//gets(line);
printf("Type title of the %d book\n",c);
fgets(library[i].title,sizeof(library[i].title),stdin);
printf("Type genre of the %d book\n",c);
fgets(library[i].genre,sizeof(library[i].genre),stdin);
printf("Type author's name of the %d book\n",c);
fgets(library[i].aname,sizeof(library[i].aname),stdin);
printf("Type the year of publishing of the %d book\n",c);
fflush(stdin);
scanf("%i",&library[i].year);
fflush(stdin);
c++;
}
}
void print(struct book library[10])
{
int i=0;
printf("\nThis is your library:");
for(i=0;i<10;i++)
{
printf("Title\tGenre\tAuthor's name\tYear of publishing\n");
printf("%s, %20s, %20s, %20d", library[i].title, library[i].genre, library[i].aname, library[i].year);
}
}
void search (struct book library[10])
{
int i;
int bool=0;
char b[50];
printf ("What title you search?");
fflush(stdin);
fgets(b,100,stdin);
for(i=0;i<10;i++)
{
if(strcmp(library[i].title,b)==0)
{
printf("Title: %s, Author: %s, Genre: %s, Year: %i",&library[i].title, &library[i].aname, &library[i].genre, &library[i].year);
bool=1;
}
}
if(bool==0)
printf("No book\n");
}
void menu()
{
char c;
int i;
printf("What would you like to do? \n(s)earch for a book or (p)rint data?\n");
c=getchar();
switch(c)
{
case 's':
search;
break;
case 'p':
print;
default:
printf("Incorrect char\n");
}
fflush(stdin);
menu;
}
void main()
{
int index = 0;
int *indptr;
indptr =&index;
struct book library[10];
void typing(library, indptr);
void menu(struct book library[10]);
}