answersLogoWhite

0

#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

12y ago

What else can I help you with?

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 is a field that might be used in a database about students?

A simple field in this database would be the name of students, though first and last names are often separated into two fields.


How do you classify the student database?

A student database can be classified based on the information it stores, such as student IDs, names, contact details, grades, attendance records, and any other relevant data. It can also be classified based on the organization it serves, such as a school, college, or university. Additionally, the database can be classified by its functionality, such as tracking academic performance, managing student admissions, or generating reports.


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

homa


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

no


What about aria's brother?

arias is a student at the international performing arts academy


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.


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.