Question

Write a C program to store students records in a file.

30 Nov 2017
Answer :
Word Count : 591

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Structure to store student information
struct Student {
    int roll_no;
    char name[100];
    float marks;
};

// Function to write student records to a file
void writeToFile() {
    FILE *file;
    struct Student student;
    
    file = fopen("student_records.dat", "wb");
    if (file == NULL) {
        printf("Error opening file.\n");
        return;
    }
    
    int n;
    printf("Enter the number of students: ");
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) {
        printf("\nEnter details of student %d:\n", i + 1);
        printf("Roll No: ");
        scanf("%d", &student.roll_no);
        getchar(); // to clear the newline character left by scanf
        printf("Name: ");
        fgets(student.name, sizeof(student.name), stdin);
        student.name[strcspn(student.name, "\n")] = '\0'; // Remove newline character

_______ _________ ________ ________ _____.
___ _______ _______ __________ ________.
____ ________ _______ _______ _______ __________ __________ _________ __________.
_______ _______ _________ ________ _________ ___ _______ _______ _______ ____.
_________ _____ ________ __________ ____ ______ _____ _________ ____ ______ ___.
_______ __________ ___ _________ _______ _______ ____ ________ _________.
__________ __________ _______ _______ __________ _____ __________ _______ ________ ___ _______.
__________ _________ ______ _______ _________ ________ _______ __________ _____ _____ __________.
____ ____ ____ _________ __________ ____ ___ ______ ___ ___ ________ ______.
_____ __________ ______ ________ __________ ___.
______ ________ _______ ______ ______ _______ _____ ___ ____ __________.
_________ ____ ___ ___ ____ ____ ______ _____ __________ _____ ___ _______.
_______ ___ _________ __________ ________ __________ _________.
_______ __________ _________ _____ ___ ________ ___.
_______ _______ _______ ______ _________ ___ ____ ________ ___ ______ ___.
_______ ____ _________ _________ ____ _____.
_______ ______ ________ ______ _________ ___ _________ ________ ________ ______ __________.
__________ ________ __________ _________ _____ ________ ____ __________ ____ ________.
__________ ___ ____ _________ __________.
__________ ______ _________ ___ ___ _____ ________.
_____ __________ ___ ___ _______ _______ _________ ______ _____ _______ ________.
________ ___ __________ ____ _____.
__________ ___ ___ ________ ________ _____ ____ _______ ___.
______ __________ ____ _______ ___ ______ _________ __________ _____ _____.
______ ___ _______ ___ ______ _______ ________ _______ _______ _______ ____.
__________ ______ ______ ___ ________ ____ ______ ____ _____.
______ __________ __________ _______ ___ ____ _________ ______ ______ ___ ___ _______.
________ _________ _________ ___ _________ ______ ____.
_________ _________ _______ _________ ______ ______ ___ ______ _______.
____ _____ _________ _______ ______ ____ _________ ________.
____ ___ ______ _______ ______ ______.
__________ ___ _______ _____ ______ ___ ___ _______ ______ ______ _________ ___.
_________ ________ ________ ________ _____ ____ ____ ___ _______.
_____ ____ ______ ____ ______ ______ _______ _______ _________.
__________ _____ ___ _____ ________ ________ __________ ________.
_____ ______ _______ ______ _________ __________ _________ _______ ______ _______ ________.
_________ _____ ________ ___ _____ _________ ____.
________ ______ _____ ____ ______ ________ __________ _____ _____ __________ _____ ______.
_____ ___ ___ ____ _________ __________ __________ _______ _________.
____ ____ ______ ___ _________ _______.
________ ___ ______ _________ _____ _________ _____ _______ ____ _________ ______.
________ ___ _________ ___ _______ ______ ____ ___.
__________ ______ ____ _______ _____ __________ ______.
________ ________ __________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
Top
📞
Call Support Instant phone assistance IGNOU MCS 11 2010 - Write a C program to store students records in a file. | IGNOU Academy
→
🟢
WhatsApp Chat Fast live messaging
→
Email Us Business enquiries & support
→