answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<string.h>

#include<conio.h>

/*Structure created for student record*/

typedef struct student

{

int roll_no;

char name[30];

}student;

void copy(char [],char []);

/*Function to create or insert the records

In write mode it creates new file and write the records

In append mode it insert the records in already created file

*/

void create(char mode[])

{

student stud;

FILE *fp;

int total,i;

fp=fopen("Records.txt",mode);

if(fp==NULL)

printf("\nUnable to open the file");

else

{

printf("\nHow many record(s) do you want to enter\t");

scanf("%d",&total);

for(i=0;i<total;i++)

{

printf("Enter the roll no and name\t");

scanf("%d %s",&stud.roll_no,stud.name);

fprintf(fp,"\n\t%d \t%s",stud.roll_no,stud.name);

}

printf("\nRecord(s) inserted successfully...");

fclose(fp);

}

}

/*This function displays the record of file passed to it

using fread and fwrite*/

void display(char filename[])

{

student stud;

FILE *fp;

fp=fopen(filename,"r+");

if(fp==NULL)

printf("\nUnable to to open file");

else

{

while(fscanf(fp,"\n\t%d \t%s",&stud.roll_no,stud.name)!=EOF)

{

printf("\n%d\t%s",stud.roll_no,stud.name);

}

}

fclose(fp);

}

/*Function to search the records

It returns -1 if search is unsuccessful

else return 0*/

int search(int roll)

{

student stud;

FILE *fp;

fp=fopen("Records.txt","r+");

if(fp==NULL)

printf("\nUnable to to open file");

else

{

while(fscanf(fp,"\n\t%d \t%s",&stud.roll_no,stud.name)!=EOF)

{

if(roll 0)

printf("\n\tREnamed...\n\n");

//fclose(fp1);

printf("\n\nRecords deleted successfully...");

}

else

printf("\nOops! Record not found...");

}

}

/*Function to copy all records from one file to other*/

void copy(char f1[],char f2[])

{

student stud;

FILE *fp1,*fp2;

fp1=fopen(f1,"r+");

fp2=fopen(f2,"w+");

if(fp1==NULL fp2==NULL)

printf("\nUnable to to open file");

else

{

while(fscanf(fp1,"\n\t%d \t%s",&stud.roll_no,stud.name)!=EOF)

{

fprintf(fp2,"\n\t%d \t%s",stud.roll_no,stud.name);

}

fclose(fp1);

fclose(fp2);

printf("\n\nRecords copied successfully...");

printf("\nContents are...\n");

display(f2);

}

}

FILE *fp;

/*Main function starts*/

void main()

{

int ch,i,roll;

//if(!(fp=fopen("record.txt","r+")))

//fp=fopen("Record.txt","w+");

do

{

clrscr();

/*Menu for the function*/

printf("\n*** MENU ***");

printf("\n1.Create");

printf("\n2.Insert");

printf("\n3.Update");

printf("\n4.Search");

printf("\n5.Display");

printf("\n6.Copy");

printf("\n7.Delete");

printf("\n8.Exit");

printf("\nEnter your choice\t");

scanf("%d",&ch);

switch(ch)

{

case 1:create("w+");break;

case 2:create("a+");break;

case 3:modify();break;

case 4:

printf("\nEnter the roll no to be searched\t");

scanf("%d",&roll);

i=search(roll);

if(i==-1)

printf("\nOops! Record not found");

break;

case 5:display("Records.txt");break;

case 6:copy("Records.txt","Newcopy.txt");break;

case 7:Delete();break;

case 8:break;

default:printf("\nPlease enter proper choice...");

}

getch();

}while(ch!=8); /*Program terminates on choice 8*/

}

Written by: Fabianski Benjamin

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Such a project would require knowledge about the concept of files, structures and arrays. It involves a small amount of planning, particularly if you're relatively new to programming. If the database is to use a specific architecture, including SQL, you will need to refer to documentation for that API and examples supplied online that you can find using any Web search engine like Google.

Your first step is to decide which elements you need inside the structure containing the student data. This can include the student's name, the courses they're taking, grades in each course, and overall GPA.

Once the structure has been created, if an interface is required you'll need to create the layout for the interface. Is this is a console-mode application or graphical (GUI) application? Once that question has been answered, you can decide on precisely how to accept data from the user. GUIs make this simple if you have access to a tool that lets you create dialogs or windows with controls.

Once the user has entered the student data into a form, you'll want to store that form data in a file. To do this: open the file to append to it; write the data; and close the file. Since you're using structures, it's probably easiest to simply fill out a structure with the information the user has entered into edit boxes, and then write that structure to the file.

This has employed a bottom-up approach to programming. You began with the planning, and continued adding pieces to your developing program.

The user must be able to edit the data as well. For this, you'll need to seek to a specific record number within the file, and then read the data into a structure and display it in a form. Once the user has finished editing the data, they click "save", which seeks back to that same position and writes the data.

When you write any data to the file, it's important that you close it. Otherwise, if your program or computer crashes, there's a good chance that data will be lost and some clusters will go missing on your hard disk until a disk scanner is run (at least under Windows, that is).

See the related links for more information on C structures, files and arrays.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a c program for performing file operations on student database?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What problems could occur if a student database is not maintained?

What problem can occur if a student database is not maintained


What's the best calculator for a college student majoring in Physics?

The TI-89 for the money is probably the best calculator for a student majoring in Physics -- the fact that the graphing capability allows you to see the input is very useful when performing multi-stpe operations.


In access what is a primary key a street name in an address database a postal code in an address database a car model in a motor vehicle dept database a student id in a college r?

student ID


What is a matriculated student?

It is a student who has declared and been accepted into a specific program of study.It is a student who has declared and been accepted into a specific program of study.It is a student who has declared and been accepted into a specific program of study.It is a student who has declared and been accepted into a specific program of study.It is a student who has declared and been accepted into a specific program of study.It is a student who has declared and been accepted into a specific program of study.


Flowchart for student database using structure?

transpiration


What database fields would be the most suitable to use as a primary key Student Name?

It is recommended to use a unique identifier such as a student ID number as a primary key instead of the student name. This is because names are not always unique and can change, while an ID is a reliable and stable way to uniquely identify each student's record in the database.


Is a student form suitable for a database field to use as a primary key?

no


How do you make coding of student registration database using java?

homa


What about aria's brother?

arias is a student at the international performing arts academy


List two examples of fields in database holding details about school pupils?

Student Information System (SIS) database: This database typically includes fields such as student names, dates of birth, addresses, contact details, parent/guardian information, enrollment information, attendance records, grade levels, and academic performance. Class Rosters database: This database may contain fields such as student IDs, course enrollments, teacher names, class schedules, and grades or assessment scores. It helps to track the specific classes and courses in which each student is currently enrolled, as well as their performance in those classes.


What type of software uses college to keep track of student records?

database software


Which specialized database might a student use to find articles on the environment and ecology?

Greenfile