Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Students Information Project in C Language Using Structure With
- File Handling Funcation */
- #include<conio.h>
- #include<stdio.h>
- void add();
- void display();
- void search();
- void del();
- void rep();
- void close();
- void dev();
- FILE *fp,*ft;
- char ch;
- struct student
- {
- char *sroll[5];
- char *sfname[15], *slname[15], *sstream[15], *sdob[15], *sadd[30], *scity[20];
- char *smobile[15];
- };
- void main()
- {
- int c;
- char ch1;
- char another;
- fp= fopen("students.rec","a");
- clrscr();
- fflush(stdin);
- do
- {
- //getch();
- clrscr();
- printf("\n-------------------------------------------------------------");
- printf("\n--------------------Students Information---------------------");
- printf("\n-------------------------------------------------------------");
- printf("\n 1. Add Student Information");
- printf("\n 2. Display Student Information");
- printf("\n 3. Search Student Information");
- printf("\n 4. Delete Student Information");
- printf("\n 5. Edit/Replace Student Information");
- printf("\n 6. Exit");
- printf("\n-------------------------------------------------------------");
- printf("\n---------Note :Don't Enter Space in Add Information ---------");
- printf("\n-------------------------------------------------------------");
- if(fp == NULL)
- {
- printf("\n Error in Openinng File ");
- }
- else
- {
- printf("\n Text File has been Created Successfully");
- }
- printf("\n-------------------------------------------------------------");
- printf("\n Enter Choice : ");
- scanf("%d",&c);
- printf("-------------------------------------------------------------");
- switch (c)
- {
- case 1:
- add();
- break;
- case 2:
- display();
- break;
- case 3:
- search();
- break;
- case 4:
- del();
- break;
- case 5:
- rep();
- break;
- case 6:
- printf("\n Exit Project");
- break;
- default:
- printf("\n Enter Valid Options");
- break;
- }
- printf("\n Do You Want To Continue Project Y or N : ");
- fflush(stdin);
- scanf("%c",&ch1);
- }while(ch1=='y' || ch1=='Y');
- fclose(fp);
- getch();
- }
- // (1) Add Students Details
- void add()
- {
- struct student i;
- //fprintf(fp,"Roll FirstName LastName Stream DateOfBirth MobileNo Address City");
- printf("\n Enter Student Roll \t\t: ");
- scanf("%s",i.sroll);
- //fprintf(fp,"Student Roll : %s\n",i.sroll);
- printf(" Enter Student First Name \t: ");
- scanf("%s",i.sfname);
- //fprintf(fp,"Student First Name : %s\n",i.sfname);
- printf(" Enter Student Last Name \t: ");
- scanf("%s",i.slname);
- //fprintf(fp,"Student Last Name : %s\n",i.slname);
- printf(" Enter Student Stream \t\t: ");
- scanf("%s",i.sstream);
- //fprintf(fp,"Student Stream : %s\n",i.sstream);
- printf(" Enter Student Date Of Bith dd/mm/yyyy \t: ");
- scanf("%s",i.sdob);
- //fprintf(fp,"Student Birth Date : %s\n",i.sdob);
- printf(" Enter Student Mobile No 9879845645\t: ");
- scanf("%s",i.smobile);
- //fprintf(fp,"Student Mobile No : %s\n",i.smobile);
- printf(" Enter Student Address \t\t: ");
- scanf("%s",i.sadd);
- //fprintf(fp,"Student Address : %s\n",i.sadd);
- printf(" Enter Student City \t\t: ");
- scanf("%s",i.scity);
- //fflush(stdin);
- 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);
- }
- // (2) Display Students Record
- void display()
- {
- struct student i;
- char str[999];
- fflush(stdin);
- fp=fopen("students.rec","r");
- if(fp==NULL)
- {
- printf("\n Not Open File");
- }
- /* while(!feof(fp))
- {
- fscanf(fp,"%s");
- printf(" %s ");
- } */
- printf("\n");
- while (fgets(str,999,fp) !=NULL)
- {
- printf("%s",str);
- }
- fclose(fp);
- }
- // (3) Search Students Record
- void search()
- {
- struct student i;
- char name[10];
- fp=fopen("students.rec","r");
- printf("\n Enter Name :");
- scanf("%s",&name);
- while(feof(fp))
- {
- if(strcmp(name, i.sfname) == 0)
- {
- printf("\n\t%d\t %s", i.sroll, i.sfname);
- getch();
- break;
- }
- }
- fclose(fp);
- printf("\n Work is Under Developing");
- }
- // (4) Delete Students Record
- void del()
- {
- dev();
- }
- // (5) Replace Or Edit Students Record
- void rep()
- {
- dev();
- }
- //Under Developing Message
- void dev()
- {
- printf("\n Work is Under Developing");
- }
Add Comment
Please, Sign In to add comment