Virajsinh

Students_Info_Project

Oct 4th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.19 KB | None | 0 0
  1. /* Students Information Project in C Language Using Structure With
  2. File Handling Funcation */
  3.  
  4. #include<conio.h>
  5. #include<stdio.h>
  6.  
  7. void add();
  8. void display();
  9. void search();
  10. void del();
  11. void rep();
  12. void close();
  13. void dev();
  14.  
  15. FILE *fp,*ft;
  16. char ch;
  17.  
  18. struct student
  19. {
  20.     char *sroll[5];
  21.     char *sfname[15], *slname[15], *sstream[15], *sdob[15], *sadd[30], *scity[20];
  22.     char *smobile[15];
  23. };
  24.  
  25. void main()
  26. {
  27.     int c;
  28.     char ch1;
  29.     char another;
  30.     fp= fopen("students.rec","a");
  31.  
  32.     clrscr();
  33.     fflush(stdin);
  34.  
  35.     do
  36.     {
  37.         //getch();
  38.         clrscr();
  39.  
  40.     printf("\n-------------------------------------------------------------");
  41.     printf("\n--------------------Students Information---------------------");
  42.     printf("\n-------------------------------------------------------------");
  43.     printf("\n 1. Add Student Information");
  44.     printf("\n 2. Display Student Information");
  45.     printf("\n 3. Search Student Information");
  46.     printf("\n 4. Delete Student Information");
  47.     printf("\n 5. Edit/Replace Student Information");
  48.     printf("\n 6. Exit");
  49.     printf("\n-------------------------------------------------------------");
  50.     printf("\n---------Note :Don't Enter Space in Add Information ---------");
  51.     printf("\n-------------------------------------------------------------");
  52.  
  53.     if(fp == NULL)
  54.     {
  55.         printf("\n Error in Openinng File                 ");
  56.     }
  57.     else
  58.     {
  59.         printf("\n Text File has been Created Successfully");
  60.     }
  61.     printf("\n-------------------------------------------------------------");
  62.     printf("\n Enter Choice : ");
  63.     scanf("%d",&c);
  64.     printf("-------------------------------------------------------------");
  65.  
  66.     switch (c)
  67.     {
  68.         case 1:
  69.         add();
  70.         break;
  71.  
  72.         case 2:
  73.         display();
  74.         break;
  75.  
  76.         case 3:
  77.         search();
  78.         break;
  79.  
  80.         case 4:
  81.         del();
  82.         break;
  83.  
  84.         case 5:
  85.         rep();
  86.         break;
  87.  
  88.         case 6:
  89.         printf("\n Exit Project");
  90.         break;
  91.  
  92.         default:
  93.         printf("\n Enter Valid Options");
  94.         break;
  95.     }
  96.  
  97.     printf("\n Do You Want To Continue Project Y or N : ");
  98.     fflush(stdin);
  99.     scanf("%c",&ch1);
  100.  
  101.     }while(ch1=='y' || ch1=='Y');
  102.  
  103.     fclose(fp);
  104.     getch();
  105. }
  106.  
  107. // (1) Add Students Details
  108. void add()
  109. {
  110.     struct student i;
  111.  
  112.     //fprintf(fp,"Roll  FirstName   LastName    Stream  DateOfBirth MobileNo    Address City");
  113.  
  114.     printf("\n Enter Student Roll \t\t: ");
  115.     scanf("%s",i.sroll);
  116.     //fprintf(fp,"Student Roll : %s\n",i.sroll);
  117.  
  118.     printf(" Enter Student First Name \t: ");
  119.     scanf("%s",i.sfname);
  120.     //fprintf(fp,"Student First Name : %s\n",i.sfname);
  121.  
  122.     printf(" Enter Student Last Name \t: ");
  123.     scanf("%s",i.slname);
  124.     //fprintf(fp,"Student Last Name : %s\n",i.slname);
  125.  
  126.     printf(" Enter Student Stream \t\t: ");
  127.     scanf("%s",i.sstream);
  128.     //fprintf(fp,"Student Stream : %s\n",i.sstream);
  129.  
  130.     printf(" Enter Student Date Of Bith dd/mm/yyyy \t: ");
  131.     scanf("%s",i.sdob);
  132.     //fprintf(fp,"Student Birth Date : %s\n",i.sdob);
  133.  
  134.     printf(" Enter Student Mobile No 9879845645\t: ");
  135.     scanf("%s",i.smobile);
  136.     //fprintf(fp,"Student Mobile No : %s\n",i.smobile);
  137.  
  138.     printf(" Enter Student Address \t\t: ");
  139.     scanf("%s",i.sadd);
  140.     //fprintf(fp,"Student Address : %s\n",i.sadd);
  141.  
  142.     printf(" Enter Student City \t\t: ");
  143.     scanf("%s",i.scity);
  144.  
  145.     //fflush(stdin);
  146.     fprintf(fp,"\n%s %s\t%s\t%s\t%s\t%s\t%s\t%s\n",i.sroll,i.sfname,i.slname,i.sstream,i.sdob,i.smobile,i.sadd,i.scity);
  147. }
  148.  
  149. // (2) Display Students Record
  150. void display()
  151. {
  152.     struct student i;
  153.     char str[999];
  154.     fflush(stdin);
  155.     fp=fopen("students.rec","r");
  156.  
  157.     if(fp==NULL)
  158.     {
  159.         printf("\n Not Open File");
  160.     }
  161.  
  162.     /*  while(!feof(fp))
  163.     {
  164.         fscanf(fp,"%s");
  165.         printf(" %s ");
  166.     } */
  167.     printf("\n");
  168.     while (fgets(str,999,fp) !=NULL)
  169.     {
  170.         printf("%s",str);
  171.     }
  172.     fclose(fp);
  173. }
  174.  
  175. // (3) Search Students Record
  176. void search()
  177. {
  178.     struct student i;
  179.     char name[10];
  180.     fp=fopen("students.rec","r");
  181.     printf("\n Enter Name :");
  182.     scanf("%s",&name);
  183.     while(feof(fp))
  184.     {
  185.         if(strcmp(name, i.sfname) == 0)
  186.         {
  187.             printf("\n\t%d\t %s", i.sroll, i.sfname);
  188.             getch();
  189.             break;
  190.         }
  191.     }
  192.     fclose(fp);
  193.     printf("\n Work is Under Developing");
  194. }
  195.  
  196. // (4) Delete Students Record
  197. void del()
  198. {
  199.     dev();
  200. }
  201.  
  202.  
  203. // (5) Replace Or Edit Students Record
  204. void rep()
  205. {
  206.     dev();
  207. }
  208.  
  209. //Under Developing Message
  210. void dev()
  211. {
  212.     printf("\n Work is Under Developing");
  213. }
Add Comment
Please, Sign In to add comment