fork download
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define CUSHION 50 /* for array sizes*/
#define RECLMT 20 /* amount of records */

/*------------------DECLARATIONS----------------------*/
struct book
{
    char title[CUSHION];
    char firstname[CUSHION];
    char lastname[CUSHION];
    char isbn[13]; /*ISBN Number consists of 13 numbers*/
    char publisher[CUSHION];
    char dop[4]; /*only the year needed*/
};

struct book Book[RECLMT]; /*20 records*/

int populate(void);

void welcome_menu(void); /* Options menu */

int choice(char);

char * stringer(void); /* prototype for input interface */

/*----------------------------------------------------------------------*/

/* MAIN STARTS HERE */
int main()
{
    welcome_menu();
	
	return 0;
}

/* MAIN ENDS HERE */

/*-----------------FUNCTIONS------------------------------------------*/
/* start menu */
void welcome_menu(void)
{
	char p;
    printf("  ******************************************\n");
    printf("  * Welcome to the Mile End Library System *\n");
    printf("  ******************************************\n\n");
    printf("Enter the number matching your intention :\n\n");
    printf("1. ADD A BOOK\n2. UPDATE AN EXISTING ENTRY\n3. BOOK SEARCH\n4. PRINT ALL FILE RECORDS\n");
	printf("\n5. (FOR ADMIN USE ONLY) POPULATE FILE\n\n");/*options keys*/

	p=getchar();
	choice(p);
}
/* end of start menu */

/* function to fill file */
int populate(void)
{
	printf("\n\nAll entries will be saved in the file, books.dat.\n\n" );

    int c=0, x=0;
	
   /*  struct book Book[RECLMT]; */

  /*  char s; */

    for(;c<=RECLMT;c++){

    printf("Title?  ");
 
	strncpy( Book[x].title , stringer(), CUSHION ); 

    printf("Author's first name?  ");

	strncpy( Book[x].firstname , stringer(), CUSHION ); 

    printf("Author's last name?  ");

   strncpy( Book[x].firstname , stringer(), CUSHION );
 
    printf("ISBN#:  ");

	strncpy( Book[x].firstname , stringer(), CUSHION );
   
    printf("Year of publication?  ");

   strncpy( Book[x].firstname , stringer(), CUSHION );

    printf("Next book -->\n");
    }
/*
books = &Book ;
FILE *bibPtr; // file handle 
bibPtr=fopen( "books.dat","w" );
	if( bibPtr == NULL )
	{  printf( "No file found.\n" );}
	else
	{
		fwrite(books,sizeof(*Book),RECLMT,bibPtr);	
}
fclose(bibPtr);*/
	return 0;
}

/* result of menu choice */
int choice(char p)
{
	switch(p)
	{
		case '1':
			break;
		case '2':
			break;
		case '3':
			break;
		case '4':
			break;
		case '5':
			/*printf("Press 5 again if you are certain\n");
			printf( "Anything else takes you back to root menu\n" );
			char t;
			(t=getchar() == '5') ?*/ populate()/*: welcome_menu*/;
			break;
		default:
			welcome_menu;
		}
	return 0 ;
}

/* A function to remedy the repeated requests in populate() */

char * stringer(void)
{
int i=0;
char s, str[CUSHION];
while ( ( s = getchar() ) !='\n' ){
		str[i++] = s;
		}
		str[i]='\0';

/* printf("you typed %s",str); */

return str;
}

Runtime error #stdin #stdout 0.01s 1728KB
stdin
5
stdout
Standard output is empty