Code

darpan.kattel

Darpan Kattel

• Jan. 2, 2022, 7:13 p.m.

Create a Structure Named student, And Perform Read And Write Operations

Perform read and write operations of Roll number, Name, Age and Address.

C

#include
#include
#include
typedef struct student
{
    int rollno;
    char name[20];
    int age;
    char address[20];
}std;
void addRecord()
{
    std s1;
    FILE *myfile;
    myfile=fopen("std.bin","ab");
    printf("Enter student's Rollno., name, age and address.\n");
    scanf("%d%s%d%s", &s1.rollnos1.name, &s1.age, &s1.address);
    fwrite(&s1sizeof(std),1,myfile);
    fclose(myfile);
    printf("Record Added");
}
void displayRecord()
{
    FILE *myfile;
    std s1;
    int count=0;
    myfile=fopen("std.bin","rb");
    while(fread(&s1,sizeof(std),1,myfile)==1)
    {
        printf("%d\t%s\t%d\t%s\n"s1.rollnos1.names1.ages1.address);
        count++;
    }
    fclose(myfile);
    if(count==0)
    {
        printf("No record Found");
    }
    else
    {
        printf("%d Records Found",count);
    }
}

int main()
{
    int choice;
    while(1)
    {
        system("cls");
        printf("Student Management System - Program By Simran Dhakal\n");
        printf("1. Add student\n");
        printf("2. Display student\n");
        printf("3. Exit\n");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:addRecord();
                    getch();
                    break;
            case 2:displayRecord();
                    getch();
                    break;
            case 3:exit(0);
            defaultprintf("Invalid Input");
                    getch();
        }
    }
    return 0;
}

Output:
Create a Structure Named student, And Perform Read And Write Operations | Output of C Language Code

Add comment:

Total 0 comments