fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5.  
  6. #define CUSHION 50 /* for array sizes*/
  7. #define RECLMT 20 /* amount of records */
  8.  
  9. /*------------------DECLARATIONS----------------------*/
  10. struct book
  11. {
  12. char title[CUSHION];
  13. char firstname[CUSHION];
  14. char lastname[CUSHION];
  15. char isbn[13]; /*ISBN Number consists of 13 numbers*/
  16. char publisher[CUSHION];
  17. char dop[4]; /*only the year needed*/
  18. };
  19.  
  20. struct book Book[RECLMT]; /*20 records*/
  21.  
  22. int populate(void);
  23.  
  24. void welcome_menu(void); /* Options menu */
  25.  
  26. int choice(char);
  27.  
  28. char * stringer(void); /* prototype for input interface */
  29.  
  30. /*----------------------------------------------------------------------*/
  31.  
  32. /* MAIN STARTS HERE */
  33. int main()
  34. {
  35. welcome_menu();
  36.  
  37. return 0;
  38. }
  39.  
  40. /* MAIN ENDS HERE */
  41.  
  42. /*-----------------FUNCTIONS------------------------------------------*/
  43. /* start menu */
  44. void welcome_menu(void)
  45. {
  46. char p;
  47. printf(" ******************************************\n");
  48. printf(" * Welcome to the Mile End Library System *\n");
  49. printf(" ******************************************\n\n");
  50. printf("Enter the number matching your intention :\n\n");
  51. printf("1. ADD A BOOK\n2. UPDATE AN EXISTING ENTRY\n3. BOOK SEARCH\n4. PRINT ALL FILE RECORDS\n");
  52. printf("\n5. (FOR ADMIN USE ONLY) POPULATE FILE\n\n");/*options keys*/
  53.  
  54. p=getchar();
  55. choice(p);
  56. }
  57. /* end of start menu */
  58.  
  59. /* function to fill file */
  60. int populate(void)
  61. {
  62. printf("\n\nAll entries will be saved in the file, books.dat.\n\n" );
  63.  
  64. int c=0, x=0;
  65.  
  66. /* struct book Book[RECLMT]; */
  67.  
  68. /* char s; */
  69.  
  70. for(;c<=RECLMT;c++){
  71.  
  72. printf("Title? ");
  73.  
  74. strncpy( Book[x].title , stringer(), CUSHION );
  75.  
  76. printf("Author's first name? ");
  77.  
  78. strncpy( Book[x].firstname , stringer(), CUSHION );
  79.  
  80. printf("Author's last name? ");
  81.  
  82. strncpy( Book[x].firstname , stringer(), CUSHION );
  83.  
  84. printf("ISBN#: ");
  85.  
  86. strncpy( Book[x].firstname , stringer(), CUSHION );
  87.  
  88. printf("Year of publication? ");
  89.  
  90. strncpy( Book[x].firstname , stringer(), CUSHION );
  91.  
  92. printf("Next book -->\n");
  93. }
  94. /*
  95. books = &Book ;
  96. FILE *bibPtr; // file handle
  97. bibPtr=fopen( "books.dat","w" );
  98. if( bibPtr == NULL )
  99. { printf( "No file found.\n" );}
  100. else
  101. {
  102. fwrite(books,sizeof(*Book),RECLMT,bibPtr);
  103. }
  104. fclose(bibPtr);*/
  105. return 0;
  106. }
  107.  
  108. /* result of menu choice */
  109. int choice(char p)
  110. {
  111. switch(p)
  112. {
  113. case '1':
  114. break;
  115. case '2':
  116. break;
  117. case '3':
  118. break;
  119. case '4':
  120. break;
  121. case '5':
  122. /*printf("Press 5 again if you are certain\n");
  123. printf( "Anything else takes you back to root menu\n" );
  124. char t;
  125. (t=getchar() == '5') ?*/ populate()/*: welcome_menu*/;
  126. break;
  127. default:
  128. welcome_menu;
  129. }
  130. return 0 ;
  131. }
  132.  
  133. /* A function to remedy the repeated requests in populate() */
  134.  
  135. char * stringer(void)
  136. {
  137. int i=0;
  138. char s, str[CUSHION];
  139. while ( ( s = getchar() ) !='\n' ){
  140. str[i++] = s;
  141. }
  142. str[i]='\0';
  143.  
  144. /* printf("you typed %s",str); */
  145.  
  146. return str;
  147. }
  148.  
  149.  
Runtime error #stdin #stdout 0.01s 1728KB
stdin
5
stdout
Standard output is empty