fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct student{
  6. char ID[15];
  7. char name[20];
  8. char add[20];
  9. char parname[20];
  10. int Class;
  11. long unsigned int phone_no;
  12. };
  13.  
  14. struct student stu;
  15.  
  16. ///This will set the forground color for printing in a console window.
  17. void SetColor(int ForgC)
  18. {
  19. WORD wColor;
  20. ///We will need this handle to get the current background attribute
  21. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  22. CONSOLE_SCREEN_BUFFER_INFO csbi;
  23.  
  24. ///We use csbi for the wAttributes word.
  25. if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  26. {
  27. ///Mask out all but the background attribute, and add in the forgournd color
  28. wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
  29. SetConsoleTextAttribute(hStdOut, wColor);
  30. }
  31. return;
  32. }
  33.  
  34. void ClearConsoleToColors(int ForgC, int BackC)
  35. {
  36. WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
  37. ///Get the handle to the current output buffer...
  38. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  39. ///This is used to reset the carat/cursor to the top left.
  40. COORD coord = {0, 0};
  41. ///A return value... indicating how many chars were written
  42. /// not used but we need to capture this since it will be
  43. /// written anyway (passing NULL causes an access violation).
  44. DWORD count;
  45. ///This is a structure containing all of the console info
  46. /// it is used here to find the size of the console.
  47. CONSOLE_SCREEN_BUFFER_INFO csbi;
  48. ///Here we will set the current color
  49. SetConsoleTextAttribute(hStdOut, wColor);
  50. if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
  51. {
  52. ///This fills the buffer with a given character (in this case 32=space).
  53. FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
  54. FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
  55. ///This will set our cursor position for the next print statement.
  56. SetConsoleCursorPosition(hStdOut, coord);
  57. }
  58. return;
  59. }
  60.  
  61. void SetColorAndBackground(int ForgC, int BackC)
  62. {
  63. WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
  64. SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
  65. return;
  66. }
  67.  
  68. COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);
  69. void gotoxy(int x, int y){
  70. coord.X = x; coord.Y = y; /// X and Y coordinates
  71. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  72. }
  73.  
  74. void drawRectangle(){
  75. int i, j;
  76. gotoxy(0,0);
  77. printf("%c",201);
  78. for(i = 1; i < 78; i++){
  79. gotoxy(i, 0);
  80. printf("%c",205);
  81. }
  82. gotoxy(78,0);
  83. printf("%c",187);
  84. for(i = 1; i < 25; i++){
  85. gotoxy(78, i);
  86. if(i == 6){
  87. printf("%c",185);
  88. }else{
  89. printf("%c",186);
  90. }
  91. }
  92. gotoxy(78, 25);
  93. printf("%c",188);
  94. for(i = 77; i > 0; i--){
  95. gotoxy(i,25);
  96. if(i == 35){
  97. printf("%c",202);
  98. }else{
  99. printf("%c",205);
  100. }
  101. }
  102. gotoxy(0,25);
  103. printf("%c",200);
  104. for(i = 24; i > 0; i--){
  105. gotoxy(0,i);
  106. if(i == 6){
  107. printf("%c",204);
  108. }else{
  109. printf("%c",186);
  110. }
  111. }
  112.  
  113. for(i = 1; i < 78; i++){
  114. gotoxy(i,6);
  115. if(i == 35){
  116. printf("%c",203);
  117. }else{
  118. printf("%c",205);
  119. }
  120. }
  121.  
  122. for(i = 7; i < 25; i++){
  123. gotoxy(35,i);
  124. printf("%c",186);
  125. }
  126.  
  127. }
  128.  
  129. void clearWindow(){
  130. int i,j;
  131. for(i = 37; i < 78; i++){
  132. for(j = 7; j < 25; j++){
  133. gotoxy(i,j);printf(" ");
  134. }
  135. }
  136. return;
  137. }
  138.  
  139. void window(){
  140. drawRectangle();
  141. gotoxy(28,2);
  142. SetColor(35);
  143. printf("STUDENT RECORD SYSTEM");
  144. gotoxy(20,3);
  145. printf("Tribhuvan University, Kathmandu, Nepal");
  146. gotoxy(31,4);
  147. printf("Estd.: 2016 B.S.");
  148. gotoxy(25,24);
  149. SetColor(17);
  150.  
  151. }
  152.  
  153. void get_password(char* pass)
  154. {
  155. char temp_passP[25];
  156. int i=0;
  157. while(1)
  158. {
  159. temp_passP[i]=getch();
  160. if(temp_passP[i]==13){break;}
  161. else if(temp_passP[i]==8)
  162. {
  163. if(i!=0) {
  164. printf("\b \b");
  165. i--;
  166. } else {printf("\a");}
  167. }
  168. else
  169. {
  170. printf("*");
  171. *(pass+i) = temp_passP[i];
  172. i++;
  173. }
  174. *(pass+i)='\0';
  175. }
  176. }
  177.  
  178. void use_pass_field(){
  179. int x = 15, y = 16;
  180. int use;
  181. char pass[10];
  182. SetColor(10);
  183. gotoxy(15,12);printf("The database is password protected.");
  184. gotoxy(15,13);printf(" Enter Valid username and password");
  185. SetColor(17);
  186. gotoxy(20,x);printf("USERNAME:- ");
  187. gotoxy(20,y);printf("PASSWORD:- ");
  188. gotoxy(34,x);scanf("%d",use);
  189. gotoxy(34,y);get_password(pass);
  190. }
  191.  
  192. void print_heading(const char st[]){
  193. SetColorAndBackground(31,28);
  194. gotoxy(45,8);printf("SRS : %s",st);
  195. SetColorAndBackground(17,15);
  196. }
  197.  
  198. int conf_record(char id[]){
  199. // left for you
  200. //it checks whether the entered id for
  201. //new record is already in the database.
  202. }
  203.  
  204. void add_student(){
  205. clearWindow();
  206. print_heading("Add Record");
  207. int print = 37;
  208. FILE *fp;
  209. fp = fopen("record.txt","ab+");
  210. SetColor(45);
  211. if(fp == NULL){
  212. MessageBox(0,"Error in Opening file\nMake sure your file is not write protected","Warning",0);
  213.  
  214. }else{
  215. fflush(stdin);
  216. gotoxy(print,10);printf("ID: ");gets(stu.ID);
  217. //here you can confirms the ID
  218. gotoxy(print,12);printf("Name: ");gets(stu.name);
  219. gotoxy(print,14);printf("Address: ");gets(stu.add);
  220. gotoxy(print,16);printf("Parent's name: ");gets(stu.parname);
  221. gotoxy(print,18);printf("Class: ");scanf("%d",&stu.Class);
  222. gotoxy(print,20);printf("Phone Number: ");scanf("%ld",&stu.phone_no);
  223. fwrite(&stu, sizeof(stu), 1, fp);
  224. gotoxy(40,22); printf("The record is sucessfully added");
  225. }
  226. SetColor(28);
  227. fclose(fp);
  228. return;
  229. }
  230.  
  231. void search_student(){
  232. clearWindow();
  233. print_heading("Search Record");
  234. SetColor(45);
  235. char s_id[15];
  236. int isFound = 0;
  237. gotoxy(37,10);printf("Enter ID to Search: ");fflush(stdin);
  238. gets(s_id);
  239. FILE *fp;
  240. fp = fopen("record.txt","rb");
  241. while(fread(&stu,sizeof(stu),1,fp) == 1){
  242. if(strcmp(s_id,stu.ID) == 0){
  243. isFound = 1;
  244. break;
  245. }
  246. }
  247. if(isFound == 1){
  248. gotoxy(37,12);printf("The record is Found");
  249. gotoxy(37,14);printf("ID: %s",stu.ID);
  250. gotoxy(37,15);printf("Name: %s",stu.name);
  251. gotoxy(37,16);printf("Address: %s",stu.add);
  252. gotoxy(37,17);printf("Parent's Name: %s",stu.parname);
  253. gotoxy(37,18);printf("Class: %d",stu.Class);
  254. gotoxy(37,19);printf("Phone No: %ld",stu.phone_no);
  255. }else{
  256. gotoxy(37,12);printf("Sory, No record found in the database");
  257. }
  258. SetColor(28);
  259. fclose(fp);
  260. return;
  261. }
  262.  
  263. void mod_student(){
  264. clearWindow();
  265. print_heading("Modify Record");
  266. SetColor(45);
  267. char s_id[15];
  268. int isFound = 0, print = 37;
  269. gotoxy(37,10);printf("Enter ID to Modify: ");fflush(stdin);
  270. gets(s_id);
  271. FILE *fp;
  272. fp = fopen("record.txt","rb+");
  273. while(fread(&stu, sizeof(stu),1,fp) == 1){
  274. if(strcmp(s_id, stu.ID) == 0){
  275. fflush(stdin);
  276. gotoxy(print,12);printf("ID: ");gets(stu.ID);
  277. gotoxy(print,13);printf("Name: ");gets(stu.name);
  278. gotoxy(print,14);printf("Address: ");gets(stu.add);
  279. gotoxy(print,15);printf("Parent's name: ");gets(stu.parname);
  280. gotoxy(print,16);printf("Class: ");scanf("%d",&stu.Class);
  281. gotoxy(print,17);printf("Phone Number: ");scanf("%ld",&stu.phone_no);
  282. fseek(fp,-sizeof(stu), SEEK_CUR);
  283. fwrite(&stu,sizeof(stu), 1, fp);
  284. isFound = 1;
  285. break;
  286. }
  287. }
  288. if(!isFound){
  289. gotoxy(print, 12);printf("No Record Found");
  290. }
  291. fclose(fp);
  292. SetColor(28);
  293. return;
  294. }
  295.  
  296. void gen_marksheet(){
  297. //left for further enhancement
  298. }
  299.  
  300. void delete_student(){
  301. clearWindow();
  302. print_heading("Delete Record");
  303. SetColor(45);
  304. char s_id[15];
  305. int isFound = 0, print = 37;
  306. gotoxy(37,10);printf("Enter ID to Modify: ");fflush(stdin);
  307. gets(s_id);
  308. FILE *fp, *temp;
  309. fp = fopen("record.txt","rb");
  310. temp = fopen("temp.txt", "wb");
  311. while(fread(&stu, sizeof(stu),1,fp) == 1){
  312. if(strcmp(s_id, stu.ID) == 0){
  313. fwrite(&stu,sizeof(stu),1,temp);
  314. }
  315. }
  316. fclose(fp);
  317. fclose(temp);
  318. remove("record.txt");
  319. rename("temp.txt","record.txt");
  320. gotoxy(37,12);printf("The record is sucessfully deleted");
  321. SetColor(28);
  322. return;
  323. }
  324.  
  325. void main_window(){
  326. int choice;
  327. SetColor(28);
  328. int x = 2;
  329. while(1){
  330. gotoxy(x,8);printf("1. Add Student");
  331. gotoxy(x,10);printf("2. Search Student");
  332. gotoxy(x,12);printf("3. Modify Student Record");
  333. gotoxy(x,14);printf("4. Generate Marksheet");
  334. gotoxy(x,16);printf("5. Delete Student Record");
  335. gotoxy(x,18);printf("6. Change password");
  336. gotoxy(x,20);printf("7. Exit");
  337. gotoxy(x,22);printf("Enter your choice: ");
  338. scanf("%d",&choice);
  339. switch(choice){
  340. case 1:
  341. add_student();
  342. break;
  343. case 2:
  344. search_student();
  345. break;
  346. case 3:
  347. mod_student();
  348. break;
  349. case 4:
  350. break;
  351. case 5:
  352. delete_student();
  353. break;
  354. case 6:
  355. break;
  356. case 7:
  357. exit(0);
  358. break;
  359. default:
  360. break;
  361. }
  362.  
  363. }
  364.  
  365. }
  366.  
  367. int main(){
  368. ClearConsoleToColors(17,15);
  369. SetConsoleTitle("Programming-technique.blogspot.com - Student Record System");
  370. window();
  371. //use_pass_field();
  372. main_window();
  373. return 0;
  374. }
  375.  
  376.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'SetColor':
prog.c:19:6: error: unknown type name 'WORD'
      WORD wColor;
      ^
prog.c:21:6: error: unknown type name 'HANDLE'
      HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
      ^
prog.c:21:6: warning: implicit declaration of function 'GetStdHandle' [-Wimplicit-function-declaration]
prog.c:21:36: error: 'STD_OUTPUT_HANDLE' undeclared (first use in this function)
      HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
                                    ^
prog.c:21:36: note: each undeclared identifier is reported only once for each function it appears in
prog.c:22:6: error: unknown type name 'CONSOLE_SCREEN_BUFFER_INFO'
      CONSOLE_SCREEN_BUFFER_INFO csbi;
      ^
prog.c:25:6: warning: implicit declaration of function 'GetConsoleScreenBufferInfo' [-Wimplicit-function-declaration]
      if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
      ^
prog.c:28:25: error: request for member 'wAttributes' in something not a structure or union
           wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
                         ^
prog.c:29:11: warning: implicit declaration of function 'SetConsoleTextAttribute' [-Wimplicit-function-declaration]
           SetConsoleTextAttribute(hStdOut, wColor);
           ^
prog.c: In function 'ClearConsoleToColors':
prog.c:36:6: error: unknown type name 'WORD'
      WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
      ^
prog.c:38:6: error: unknown type name 'HANDLE'
      HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
      ^
prog.c:38:36: error: 'STD_OUTPUT_HANDLE' undeclared (first use in this function)
      HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
                                    ^
prog.c:40:6: error: unknown type name 'COORD'
      COORD coord = {0, 0};
      ^
prog.c:40:6: warning: excess elements in scalar initializer
prog.c:40:6: warning: (near initialization for 'coord')
prog.c:44:6: error: unknown type name 'DWORD'
      DWORD count;
      ^
prog.c:47:6: error: unknown type name 'CONSOLE_SCREEN_BUFFER_INFO'
      CONSOLE_SCREEN_BUFFER_INFO csbi;
      ^
prog.c:53:11: warning: implicit declaration of function 'FillConsoleOutputCharacter' [-Wimplicit-function-declaration]
           FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
           ^
prog.c:53:48: error: 'TCHAR' undeclared (first use in this function)
           FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
                                                ^
prog.c:53:55: error: expected ')' before numeric constant
           FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
                                                       ^
prog.c:54:11: warning: implicit declaration of function 'FillConsoleOutputAttribute' [-Wimplicit-function-declaration]
           FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
           ^
prog.c:54:51: error: request for member 'wAttributes' in something not a structure or union
           FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
                                                   ^
prog.c:54:69: error: request for member 'dwSize' in something not a structure or union
           FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
                                                                     ^
prog.c:54:85: error: request for member 'dwSize' in something not a structure or union
           FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count );
                                                                                     ^
prog.c:56:11: warning: implicit declaration of function 'SetConsoleCursorPosition' [-Wimplicit-function-declaration]
           SetConsoleCursorPosition(hStdOut, coord);
           ^
prog.c: In function 'SetColorAndBackground':
prog.c:63:6: error: unknown type name 'WORD'
      WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
      ^
prog.c:64:43: error: 'STD_OUTPUT_HANDLE' undeclared (first use in this function)
      SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
                                           ^
prog.c: At top level:
prog.c:68:1: error: unknown type name 'COORD'
 COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);
 ^
prog.c:68:1: warning: excess elements in scalar initializer
prog.c:68:1: warning: (near initialization for 'coord')
prog.c: In function 'gotoxy':
prog.c:70:10: error: request for member 'X' in something not a structure or union
     coord.X = x; coord.Y = y; /// X and Y coordinates
          ^
prog.c:70:23: error: request for member 'Y' in something not a structure or union
     coord.X = x; coord.Y = y; /// X and Y coordinates
                       ^
prog.c:71:43: error: 'STD_OUTPUT_HANDLE' undeclared (first use in this function)
     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
                                           ^
prog.c: In function 'drawRectangle':
prog.c:75:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
prog.c: In function 'get_password':
prog.c:159:13: warning: implicit declaration of function 'getch' [-Wimplicit-function-declaration]
             temp_passP[i]=getch();
             ^
prog.c: In function 'use_pass_field':
prog.c:188:5: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
     gotoxy(34,x);scanf("%d",use);
     ^
prog.c: In function 'add_student':
prog.c:212:9: warning: implicit declaration of function 'MessageBox' [-Wimplicit-function-declaration]
         MessageBox(0,"Error in Opening file\nMake sure your file is not write protected","Warning",0);
         ^
prog.c:216:9: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gotoxy(print,10);printf("ID: ");gets(stu.ID);
         ^
prog.c:218:9: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gotoxy(print,12);printf("Name: ");gets(stu.name);
         ^
prog.c:219:9: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gotoxy(print,14);printf("Address: ");gets(stu.add);
         ^
prog.c:220:9: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
         gotoxy(print,16);printf("Parent's name: ");gets(stu.parname);
         ^
prog.c: In function 'search_student':
prog.c:238:5: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
     gets(s_id);
     ^
prog.c: In function 'mod_student':
prog.c:270:5: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
     gets(s_id);
     ^
prog.c:276:13: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
             gotoxy(print,12);printf("ID: ");gets(stu.ID);
             ^
prog.c:277:13: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
             gotoxy(print,13);printf("Name: ");gets(stu.name);
             ^
prog.c:278:13: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
             gotoxy(print,14);printf("Address: ");gets(stu.add);
             ^
prog.c:279:13: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
             gotoxy(print,15);printf("Parent's name: ");gets(stu.parname);
             ^
prog.c: In function 'delete_student':
prog.c:307:5: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
     gets(s_id);
     ^
prog.c:305:22: warning: unused variable 'print' [-Wunused-variable]
     int isFound = 0, print = 37;
                      ^
prog.c:305:9: warning: unused variable 'isFound' [-Wunused-variable]
     int isFound = 0, print = 37;
         ^
prog.c: In function 'main':
prog.c:369:5: warning: implicit declaration of function 'SetConsoleTitle' [-Wimplicit-function-declaration]
     SetConsoleTitle("Programming-technique.blogspot.com - Student Record System");
     ^
prog.c: In function 'conf_record':
prog.c:202:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty