Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program that performs add, edit, delete, display and search date from file

Posted By: Easy Tutor     Category: C Programming     Views: 76172

Write a program that performs below operations file that stores Bio-data.

1) Add
2) Edit
3) Delete
4) Display
5) Search

Code for Program that performs add, edit, delete, display and search date from file in C Programming

#include <stdio.h>
#include <conio.h>

struct biodata{
       int recno,age;
       char name[20],sex;
       float salary;
};


void main(){
     void addData(void);
     void delData(void);
     void showAll(void);
     void showRecord(void);
     void alterData(void);

     char choice;
     clrscr();

     while(1){
      clrscr();
      textcolor(BLACK);
      cprintf("         B I O - D A T A\r\n");
      printf("\n\n*****CHOOSE YOUR CHOICE*****\n");
      printf("1) ADD DATA\n");
      printf("2) DELETE DATA\n");
      printf("3) SHOW ALL\n");
      printf("4) SHOW RECORD\n");
      printf("5) ALTER DATA\n");
      printf("6) Exit \n");
      printf("Enter your choice : ");
      fflush(stdin);
      choice = getche();
      switch(choice){
         case'1' :   //call add data
                addData();
                break;
         case'2' :   //call delete databreak;
         case'3' :  //call show all data
                showAll();
                break;
         case'4' :  //call show record
                showRecord();
                break;
         case'5' :   //call alter databreak;
         case'6' :
         case 27  :     clrscr();
                gotoxy(25,10);
                _setcursortype(_NOCURSOR);
                textcolor(LIGHTMAGENTA);
                cprintf("THANKS FOR USING THIS SOFTWARE");
                getch();
                exit(1);
      }
     }

}


//Adding Record to Filevoid addData(){
     FILE *fp;
     struct biodata obj;
     fp = fopen("biodata.txt","a+t");
     clrscr();
     printf("\n*****ADDING DATA*****\n");
     printf("\nEnter Record No : ");
     scanf("%d",&obj.recno);
     printf("Enter Name : ");
     fflush(stdin);
     scanf("%s",obj.name);
     printf("Enter age : ");
     scanf("%d",&obj.age);
     fflush(stdin);
     printf("Enter Sex : ");
     scanf("%c",&obj.sex);
     printf("Enter Salary : ");
     scanf("%f",&obj.salary);
     fscanf(stdin,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.sex,&obj.salary);
     fprintf(fp,"%d %s %d %c %f",obj.recno,obj.name,obj.age,obj.sex,obj.salary);
     fclose(fp);
}

void showRecord(){
     FILE *fp;
     struct biodata obj;
     int rec;
     long pos;
     fp = fopen("biodata.txt","r");
     clrscr();
     printf("\n*****SHOWING SPECIFIC RECORD*****\n");
     printf("\nEnter Record No : ");
     scanf("%d",&rec);
     pos = rec * sizeof(obj);
     fseek(fp,pos,SEEK_SET);
     if(feof(fp)==0)
    printf("\n\nNO DATA FOUND\n");
     else{
     fscanf(fp,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.sex,&obj.salary);
     printf("\n\n\tRecord No :  %d\n",obj.recno);
     printf("\tName : %s\n",obj.name);
     printf("\tAge  : %d\n",obj.age);
     printf("\tSex  : %c\n",obj.sex);
     printf("\tSalary : %f\n",obj.salary);
     }
     getch();
     fclose(fp);
}


void showAll(){
     FILE *fp;
     struct biodata obj;
     int totrec,i;
     fp = fopen("biodata.txt","r");
     clrscr();
     fseek(fp,0,SEEK_END);
     totrec=ftell(fp)/sizeof(obj);
     printf("\n*****SHOWING ALL RECORD*****\n");
     printf("\n\nRecord_No\tName\t\tAge\tSex\tSalary\n\n");
     printf("\n\n%d\n",totrec);
     for(i=1;i<=totrec;i++){
     fscanf(fp,"%d %s %d %c %f",&obj.recno,obj.name,&obj.age,&obj.sex,&obj.salary);
     fprintf(stdout,"%-15d %-15s %-8d %-2c %10.2f\n",obj.recno,obj.name,obj.age,obj.sex,obj.salary);
     }
     getch();
     fclose(fp);
}

  
Share: 



Easy Tutor
Easy Tutor author of Program that performs add, edit, delete, display and search date from file is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
Anup Poudel from United States Comment on: Dec 03
what the hell i am getting alot of errors

Anjali Patil from India Comment on: Sep 02
this program is not complete

Dacea Awesome from Malaysia Comment on: Nov 27
doesn't work. 30 chaaaaaaaaaaaar

View All Comments