fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <conio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6.  
  7. struct student
  8. {
  9. char ID[15];
  10. char name[20];
  11. char add[50];
  12. char parname[50];
  13. char semister[10];
  14. long unsigned int phone_no;
  15. };
  16.  
  17. struct student stu;
  18.  
  19. ///This will set the forground color for printing in a console window.
  20. void SetColor(int ForgC)
  21. {
  22. WORD wColor;
  23. ///We will need this handle to get the current background attribute
  24. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  25. CONSOLE_SCREEN_BUFFER_INFO csbi;
  26.  
  27. ///We use csbi for the wAttributes word.
  28. if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  29. {
  30. ///Mask out all but the background attribute, and add in the forgournd color
  31. wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
  32. SetConsoleTextAttribute(hStdOut, wColor);
  33. }
  34. return;
  35. }
  36.  
  37. void ClearConsoleToColors(int ForgC, int BackC)
  38. {
  39. WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
  40. ///Get the handle to the current output buffer...
  41. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  42. ///This is used to reset the carat/cursor to the top left.
  43. COORD coord = {0, 0};
  44. ///A return value... indicating how many chars were written
  45. /// not used but we need to capture this since it will be
  46. /// written anyway (passing NULL causes an access violation).
  47. DWORD count;
  48. ///This is a structure containing all of the console info
  49. /// it is used here to find the size of the console.
  50. CONSOLE_SCREEN_BUFFER_INFO csbi;
  51. ///Here we will set the current color
  52. SetConsoleTextAttribute(hStdOut, wColor);
  53. if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  54. {
  55. ///This fills the buffer with a given character (in this case 32=space).
  56. FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
  57. FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
  58. ///This will set our cursor position for the next print statement.
  59. SetConsoleCursorPosition(hStdOut, coord);
  60. }
  61. return;
  62. }
  63.  
  64. void SetColorAndBackground(int ForgC, int BackC)
  65. {
  66. WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
  67. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
  68. return;
  69. }
  70.  
  71. COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);
  72. void gotoxy(int x, int y)
  73. {
  74. coord.X = x;
  75. coord.Y = y; /// X and Y coordinates
  76. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  77. }
  78.  
  79. void drawRectangle()
  80. {
  81. int i, j;
  82. gotoxy(0,0);
  83. printf("%c",201);
  84. for(i = 1; i < 78; i++)
  85. {
  86. gotoxy(i, 0);
  87. printf("%c",205);
  88. }
  89. gotoxy(78,0);
  90. printf("%c",187);
  91. for(i = 1; i < 25; i++)
  92. {
  93. gotoxy(78, i);
  94. if(i == 6)
  95. {
  96. printf("%c",185);
  97. }
  98. else
  99. {
  100. printf("%c",186);
  101. }
  102. }
  103. gotoxy(78, 25);
  104. printf("%c",188);
  105. for(i = 77; i > 0; i--)
  106. {
  107. gotoxy(i,25);
  108. if(i == 35)
  109. {
  110. printf("%c",202);
  111. }
  112. else
  113. {
  114. printf("%c",205);
  115. }
  116. }
  117. gotoxy(0,25);
  118. printf("%c",200);
  119. for(i = 24; i > 0; i--)
  120. {
  121. gotoxy(0,i);
  122. if(i == 6)
  123. {
  124. printf("%c",204);
  125. }
  126. else
  127. {
  128. printf("%c",186);
  129. }
  130. }
  131.  
  132. for(i = 1; i < 78; i++)
  133. {
  134. gotoxy(i,6);
  135. if(i == 35)
  136. {
  137. printf("%c",203);
  138. }
  139. else
  140. {
  141. printf("%c",205);
  142. }
  143. }
  144.  
  145. for(i = 7; i < 25; i++)
  146. {
  147. gotoxy(35,i);
  148. printf("%c",186);
  149. }
  150.  
  151. }
  152.  
  153. void clearWindow()
  154. {
  155. int i,j;
  156. for(i = 37; i < 78; i++)
  157. {
  158. for(j = 7; j < 25; j++)
  159. {
  160. gotoxy(i,j);
  161. printf(" ");
  162. }
  163. }
  164. return;
  165. }
  166.  
  167. void window()
  168. {
  169. drawRectangle();
  170. gotoxy(28,2);
  171. SetColor(35);
  172. printf("STUDENT RECORD SYSTEM");
  173. gotoxy(20,3);
  174. printf("ENTER University Of Science & Technology ,Bangladesh");
  175. gotoxy(31,4);
  176. printf("Depertment of CSE.");
  177. gotoxy(25,24);
  178. SetColor(17);
  179.  
  180. }
  181.  
  182.  
  183.  
  184. void print_heading(const char st[])
  185. {
  186. SetColorAndBackground(31,28);
  187. gotoxy(45,8);
  188. printf("SRS : %s",st);
  189. SetColorAndBackground(17,15);
  190. }
  191.  
  192.  
  193.  
  194. void add_student()
  195. {
  196. clearWindow();
  197. print_heading("Add Record");
  198. int print = 37;
  199. FILE *fp;
  200. fp = fopen("record.txt","ab+");
  201. SetColor(45);
  202. if(fp == NULL)
  203. {
  204. MessageBox(0,"Error in Opening file\nMake sure your file is not write protected","Warning",0);
  205.  
  206. }
  207. else
  208. {
  209. fflush(stdin);
  210. gotoxy(print,10);
  211. printf("ID: ");
  212. gets(stu.ID);
  213. //here you can confirms the ID
  214. gotoxy(print,12);
  215. printf("Name: ");
  216. gets(stu.name);
  217. gotoxy(print,14);
  218. printf("Address: ");
  219. gets(stu.add);
  220. gotoxy(print,16);
  221. printf("Parent's name: ");
  222. gets(stu.parname);
  223. gotoxy(print,18);
  224. printf("Semister: ");
  225. gets(stu.semister);
  226. gotoxy(print,20);
  227. printf("Phone Number: ");
  228. scanf("%ld",&stu.phone_no);
  229. fwrite(&stu, sizeof(stu), 1, fp);
  230. gotoxy(40,22);
  231. printf("The record is sucessfully added");
  232. }
  233. SetColor(28);
  234. fclose(fp);
  235. return;
  236. }
  237.  
  238. void search_student()
  239. {
  240. clearWindow();
  241. print_heading("Search Record");
  242. SetColor(45);
  243. char s_id[15];
  244. int isFound = 0;
  245. gotoxy(37,10);
  246. printf("Enter ID to Search: ");
  247. fflush(stdin);
  248. gets(s_id);
  249. FILE *fp;
  250. fp = fopen("record.txt","rb");
  251. while(fread(&stu,sizeof(stu),1,fp) == 1)
  252. {
  253. if(strcmp(s_id,stu.ID) == 0)
  254. {
  255. isFound = 1;
  256. break;
  257. }
  258. }
  259. if(isFound == 1)
  260. {
  261. gotoxy(37,12);
  262. printf("The record is Found");
  263. gotoxy(37,14);
  264. printf("ID: %s",stu.ID);
  265. gotoxy(37,15);
  266. printf("Name: %s",stu.name);
  267. gotoxy(37,16);
  268. printf("Address: %s",stu.add);
  269. gotoxy(37,17);
  270. printf("Parent's Name: %s",stu.parname);
  271. gotoxy(37,18);
  272. printf("Semister: %s",stu.semister);
  273. gotoxy(37,19);
  274. printf("Phone No: %ld",stu.phone_no);
  275. }
  276. else
  277. {
  278. gotoxy(37,12);
  279. printf("Sory, No record found in the database");
  280. }
  281. SetColor(28);
  282. fclose(fp);
  283. return;
  284. }
  285.  
  286. void mod_student()
  287. {
  288. clearWindow();
  289. print_heading("Modify Record");
  290. SetColor(45);
  291. char s_id[15];
  292. int isFound = 0, print = 37;
  293. gotoxy(37,10);
  294. printf("Enter ID to Modify: ");
  295. fflush(stdin);
  296. gets(s_id);
  297. FILE *fp;
  298. fp = fopen("record.txt","rb+");
  299. while(fread(&stu, sizeof(stu),1,fp) == 1)
  300. {
  301. if(strcmp(s_id, stu.ID) == 0)
  302. {
  303. fflush(stdin);
  304. gotoxy(print,12);
  305. printf("ID: ");
  306. gets(stu.ID);
  307. gotoxy(print,13);
  308. printf("Name: ");
  309. gets(stu.name);
  310. gotoxy(print,14);
  311. printf("Address: ");
  312. gets(stu.add);
  313. gotoxy(print,15);
  314. printf("Parent's name: ");
  315. gets(stu.parname);
  316. gotoxy(print,16);
  317. printf("Semister ");
  318. gets(stu.semister);
  319. gotoxy(print,17);
  320. printf("Phone Number: ");
  321. scanf("%ld",&stu.phone_no);
  322. fseek(fp,-sizeof(stu), SEEK_CUR);
  323. fwrite(&stu,sizeof(stu), 1, fp);
  324. isFound = 1;
  325. break;
  326. }
  327. }
  328. if(!isFound)
  329. {
  330. gotoxy(print, 12);
  331. printf("No Record Found");
  332. }
  333. fclose(fp);
  334. SetColor(28);
  335. return;
  336. }
  337.  
  338.  
  339.  
  340. void delete_student()
  341. {
  342. clearWindow();
  343. print_heading("Delete Record");
  344. SetColor(45);
  345. char s_id[15];
  346. int isFound = 0, print = 37;
  347. gotoxy(37,10);
  348. printf("Enter ID to Modify: ");
  349. fflush(stdin);
  350. gets(s_id);
  351. FILE *fp, *temp;
  352. fp = fopen("record.txt","rb");
  353. temp = fopen("temp.txt", "wb");
  354. while(fread(&stu, sizeof(stu),1,fp) == 1)
  355. {
  356. if(strcmp(s_id, stu.ID) == 0)
  357. {
  358. fwrite(&stu,sizeof(stu),1,temp);
  359. }
  360. }
  361. fclose(fp);
  362. fclose(temp);
  363. remove("record.txt");
  364. rename("temp.txt","record.txt");
  365. gotoxy(37,12);
  366. printf("The record is sucessfully deleted");
  367. SetColor(28);
  368. return;
  369. }
  370.  
  371. void main_window()
  372. {
  373. int choice;
  374. SetColor(28);
  375. int x = 2;
  376. while(1)
  377. {
  378. gotoxy(x,8);
  379. printf("1. Add Student");
  380. gotoxy(x,10);
  381. printf("2. Search Student");
  382. gotoxy(x,12);
  383. printf("3. Modify Student Record");
  384. gotoxy(x,14);
  385. printf("4. Delete Student Record");
  386. gotoxy(x,16);
  387. printf("5. Exit");
  388. gotoxy(x,18);
  389. printf("Enter your choice: ");
  390. scanf("%d",&choice);
  391. switch(choice)
  392. {
  393. case 1:
  394. add_student();
  395. break;
  396. case 2:
  397. search_student();
  398. break;
  399. case 3:
  400. mod_student();
  401. break;
  402.  
  403. case 4:
  404. delete_student();
  405. break;
  406.  
  407. case 5:
  408. exit(0);
  409. break;
  410. default:
  411. break;
  412. }
  413.  
  414. }
  415.  
  416. }
  417.  
  418. int main()
  419. {
  420. ClearConsoleToColors(17,15);
  421. SetConsoleTitle("Student Record sysytem using C programming");
  422. window();
  423. //use_pass_field();
  424. main_window();
  425. return 0;
  426. }
  427.  
  428.  
  429.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:19: fatal error: conio.h: No such file or directory
 #include <conio.h>
                   ^
compilation terminated.
stdout
Standard output is empty