fork(1) download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #include<string.h>
  5.  
  6.  
  7. void addrecord();
  8. void viewrecord();
  9. void deleterecord();
  10. struct record
  11. {
  12.  
  13. char time[6];
  14. char name[30];
  15. char place[25];
  16. char note[1000];
  17.  
  18. } ;
  19.  
  20.  
  21. int main()
  22.  
  23. {
  24.  
  25. int ch;
  26. printf("\n\n\t\t\t***********************************\n");
  27. printf("\t\t\t\tWELCOME TO DIGITAL DIARY\n");
  28. printf("\t\t\t***********************************");
  29. system("color 3F");
  30. while(1)
  31.  
  32.  
  33. {
  34.  
  35. printf("\n\nMAIN MENU:");
  36. printf("\n\n\tADD RECORD\t[1]");
  37. printf("\n\tVIEW RECORD\t[2]");
  38. printf("\n\tDELETE RECORD\t[3]");
  39. printf("\n\tEXIT\t\t[4]");
  40. printf("\n\n\tENTER YOUR CHOICE:");
  41. scanf("%d",&ch);
  42.  
  43. switch(ch)
  44. {
  45. case 1:
  46. addrecord();
  47. break;
  48. case 2:
  49. viewrecord();
  50. break;
  51. case 3:
  52. deleterecord();
  53. case 4:
  54. printf("\n\n\t\tTHANK YOU. SEE YOU SOON");
  55. getch();
  56. exit(0);
  57.  
  58. default:
  59. printf("\nYOU ENTERED WRONG CHOICE..");
  60. printf("\nPRESS ANY KEY TO TRY AGAIN");
  61. getch();
  62. break;
  63.  
  64. }
  65. system("cls");
  66. }
  67. return 0;
  68. }
  69. void addrecord( )
  70.  
  71. {
  72. system("cls");
  73. FILE *fp ;
  74. char another = 'Y' ,time[10];
  75. struct record e ;
  76. char filename[15];
  77. int choice;
  78. printf("\n\n\t\t***************************\n");
  79. printf("\t\t* WELCOME TO THE ADD MENU *");
  80. printf("\n\t\t***************************\n\n");
  81. printf("\n\n\tENTER DATE OF YOUR RECORD:[yyyy-mm-dd]:");
  82. fflush(stdin);
  83. gets(filename);
  84. fp = fopen (filename, "a+" ) ;
  85. if ( fp == NULL )
  86. {
  87. fp=fopen(filename,"w+");
  88. if(fp==NULL)
  89. {
  90. printf("\nSYSTEM ERROR...");
  91. printf("\nPRESS ANY KEY TO EXIT");
  92. getch();
  93. return ;
  94. }
  95. }
  96. while ( another == 'Y'|| another=='y' )
  97. {
  98. choice=0;
  99. fflush(stdin);
  100. printf ( "\n\tENTER TIME:[hh:mm]:");
  101. scanf("%s",time);
  102. rewind(fp);
  103. while(fread(&e,sizeof(e),1,fp)==1)
  104. {
  105. if(strcmp(e.time,time)==0)
  106.  
  107. {
  108. printf("\n\tTHE RECORD ALREADY EXISTS.\n");
  109. choice=1;
  110. }
  111. }
  112. if(choice==0)
  113. {
  114. printf("\tENTER NAME:");
  115. fflush(stdin);
  116. gets(e.name);
  117. fflush(stdin);
  118. printf("\tENTER PLACE:");
  119. gets(e.place);
  120. fflush(stdin);
  121. printf("\tNOTE:");
  122. gets(e.note);
  123. fwrite ( &e, sizeof ( e ), 1, fp ) ;
  124. printf("\nYOUR RECORD IS ADDED...\n");
  125.  
  126. }
  127. printf ( "\n\tADD ANOTHER RECORD...(Y/N) " ) ;
  128. fflush ( stdin ) ;
  129. another = getchar( ) ;
  130. }
  131.  
  132. fclose ( fp ) ;
  133. printf("\n\n\tPRESS ANY KEY TO EXIT...");
  134. getch();
  135.  
  136. }
  137.  
  138. void viewrecord( )
  139. {
  140. FILE *fpte ;
  141. system("cls");
  142. struct record customer ;
  143. char time[6],choice,filename[14];
  144. int ch;
  145. printf("\n\n\t\t*******************************\n");
  146. printf("\t\t* HERE IS THE VIEWING MENU *");
  147. printf("\n\t\t*******************************\n\n");
  148.  
  149.  
  150. do
  151. {
  152. printf("\n\tENTER THE DATE OF RECORD TO BE VIEWED:[yyyy-mm-dd]:");
  153. fflush(stdin);
  154. gets(filename);
  155. fpte = fopen ( filename, "r" ) ;
  156. if ( fpte == NULL )
  157.  
  158. {
  159.  
  160. puts ( "\n\t\tTHE RECORD DOES NOT EXIST...\n" ) ;
  161. printf("\t\tPRESS ANY KEY TO EXIT...");
  162. getch();
  163. return ;
  164.  
  165. }
  166.  
  167. system("cls");
  168. printf("\n\tHOW WOULD YOU LIKE TO VIEW:\n");
  169. printf("\n\t1.WHOLE RECORD OF THE DAY.");
  170. printf("\n\t2.RECORD OF FIX TIME.\n\n");
  171. printf("\n\t\tENTER YOUR CHOICE:");
  172. scanf("%d",&ch);
  173. switch(ch)
  174. {
  175.  
  176. case 1:
  177. printf("\nTHE WHOLE RECORD FOR %s IS:",filename);
  178. while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
  179. {
  180. printf("\n");
  181. printf("\nTIME: %s",customer.time);
  182. printf("\nNAME: %s",customer.name);
  183. printf("\nPLACE: %s",customer.place);
  184. printf("\nNOTE: %s",customer.note);
  185. printf("\n");
  186. }
  187. break;
  188. case 2:
  189. fflush(stdin);
  190. printf("\nENTER TIME:[hh:mm]:");
  191. while ( fread ( &customer, sizeof ( customer ), 1, fpte ) == 1 )
  192. {
  193. if(strcmp(customer.time,time)==0)
  194. {
  195. printf("\nYOUR RECORD IS:");
  196. printf("\nTIME: %s",customer.time);
  197. printf("\nNAME: %s",customer.name);
  198. printf("\nPLACE: %s",customer.place);
  199. printf("\nNOTE: %s",customer.note);
  200. }
  201.  
  202. }
  203. break;
  204. default: printf("\nYOU TYPED SOMETHING ELSE...\n");
  205. break;
  206.  
  207. }
  208. printf("\n\nWOULD YOU LIKE TO CONTINUE VIEWING...(Y/N):");
  209. fflush(stdin);
  210. scanf("%c",&choice);
  211. }while(choice=='Y'||choice=='y');
  212. fclose ( fpte ) ;
  213. return ;
  214.  
  215. }
  216. void deleterecord( )
  217.  
  218. {
  219.  
  220. system("cls");
  221. FILE *fp,*fptr ;
  222. struct record file ;
  223. char filename[15],another = 'Y' ,time[10];;
  224.  
  225. int choice,check;
  226.  
  227. printf("\n\n\t\t*************************\n");
  228. printf("\t\t* WELCOME TO DELETE MENU*");
  229. printf("\n\t\t*************************\n\n");
  230.  
  231. while ( another == 'Y' )
  232.  
  233. {
  234.  
  235. printf("\n\n\tHOW WOULD YOU LIKE TO DELETE:\n\n");
  236. printf("\n\n\t#DELETE WHOLE RECORD\t\t\t[1]");
  237. printf("\n\t#DELETE A PARTICULAR RECORD BY TIME\t[2]\n\n");
  238. do
  239.  
  240. {
  241.  
  242. printf("\n\t\tENTER YOUR CHOICE:");
  243. scanf("%d",&choice);
  244. switch(choice)
  245.  
  246. {
  247.  
  248. case 1:
  249. printf("\n\tENTER THE DATE OF RECORD TO BE DELETED:[yyyy-mm-dd]:");
  250. fflush(stdin);
  251. gets(filename);
  252. fp = fopen (filename, "w" ) ;
  253. if ( fp == NULL )
  254. {
  255.  
  256. printf("\nTHE FILE DOES NOT EXISTS");
  257. printf("\nPRESS ANY KEY TO GO BACK.");
  258. getch();
  259. return ;
  260.  
  261. }
  262.  
  263. fclose(fp);
  264. remove(filename);
  265. printf("\nDELETED SUCCESFULLY...");
  266. break;
  267. case 2:
  268. printf("\n\tENTER THE DATE OF RECORD:[yyyy-mm-dd]:");
  269. fflush(stdin);
  270. gets(filename);
  271. fp = fopen (filename, "r" ) ;
  272. if ( fp == NULL )
  273. {
  274. printf("\nTHE FILE DOES NOT EXISTS");
  275. printf("\nPRESS ANY KEY TO GO BACK.");
  276. getch();
  277. return ;
  278. }
  279. fptr=fopen("temp","w");
  280. if(fptr==NULL)
  281.  
  282. {
  283. printf("\nSYSTEM ERROR");
  284. printf("\nPRESS ANY KEY TO GO BACK");
  285. getch();
  286. return ;
  287. }
  288. printf("\n\tENTER THE TIME OF RECORD TO BE DELETED:[hh:mm]:");
  289. fflush(stdin);
  290. while(fread(&file,sizeof(file),1,fp)==1)
  291. {
  292. if(strcmp(file.time,time)!=0)
  293. fwrite(&file,sizeof(file),1,fptr);
  294. }
  295. fclose(fp);
  296. fclose(fptr);
  297. remove(filename);
  298. rename("temp",filename);
  299. printf("\nDELETED SUCCESFULLY...");
  300. break;
  301. default:
  302. printf("\n\tYOU ENTERED WRONG CHOICE");
  303. break;
  304. }
  305. }while(choice<1||choice>2);
  306.  
  307. printf("\n\tDO YOU LIKE TO DELETE ANOTHER RECORD.(Y/N):");
  308. fflush(stdin);
  309. scanf("%c",&another);
  310. }
  311. printf("\n\n\tPRESS ANY KEY TO EXIT...");
  312.  
  313. getch();
  314.  
  315. }
  316.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:18: fatal error: conio.h: No such file or directory
 #include<conio.h>
                  ^
compilation terminated.
stdout
Standard output is empty