---
title: "96 students record; pass marks"
subject: "Computer Programming"
chapter: 10
key: "semester_1/computer_programming:file-96-students-ioe-txt"
source: https://www.bctengineer.com/q/semester_1/computer_programming/file-96-students-ioe-txt
site: BCT Engineering
---

# 96 students record; pass marks

Computer Programming · Chapter 10: Data Files

- Asked in: 2069 Asar, 8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/file-96-students-ioe-txt
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-10

## Question

Write a program in C, to read the following information for 96 students.
Student Name, Student roll number, Marks obtained(in 100)
Record all data in "ioe.txt" file, and program should print roll number and name of student who have obtained greater than or equal to 40 marks.

## Short answer

Open "ioe.txt" in write mode; loop 96 times to read name, roll, marks and write each with fprintf. Reopen in read mode; fscanf each record; if marks >=40, print roll and name. Result: Outputs list of students scoring 40 or above.

## Answer

**Logic.**
1. Open `ioe.txt` in write mode; read name, roll number and marks of 96 students in a loop and write each record with `fprintf()`.
2. Close the file, reopen it in read mode.
3. Read the records back with `fscanf()` until it no longer returns 3, and print the roll number and name of those with marks >= 40.

```c
#include <stdio.h>
#ifndef N
#define N 96
#endif

int main(void)
{
    FILE *fp;
    char name[30];
    int roll;
    float marks;

    fp = fopen("ioe.txt", "w");
    if (fp == NULL) {
        printf("Cannot create ioe.txt\n");
        return 1;
    }
    for (int i = 1; i <= N; i++) {
        printf("Student %d (name roll marks): ", i);
        scanf("%29s %d %f", name, &roll, &marks);
        fprintf(fp, "%s %d %.1f\n", name, roll, marks);
    }
    fclose(fp);

    fp = fopen("ioe.txt", "r");
    if (fp == NULL) {
        printf("Cannot open ioe.txt\n");
        return 1;
    }
    printf("\nStudents with marks >= 40\n%-6s %s\n", "Roll", "Name");
    while (fscanf(fp, "%29s %d %f", name, &roll, &marks) == 3)
        if (marks >= 40)
            printf("%-6d %s\n", roll, name);
    fclose(fp);
    return 0;
}
```

**Sample run** (N reduced to 3 with `-DN=3` for the test; the real program uses 96)

Input (entered one after another): `Ram 1 65 Sita 2 32 Hari 3 40`

```text
Students with marks >= 40
Roll   Name
1      Ram
3      Hari
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the order of operations?
   A. Write all records to ioe.txt, close, reopen for reading, then print those with marks >= 40
   B. Print results first, then write
   C. Read the file before writing
   D. Use append for printing
   Answer: A. The file is written, closed and reopened in read mode for filtering. (Key point: Two-phase approach)

2. How does the reading loop stop?
   A. When fscanf no longer returns 3
   B. After 96 reads always
   C. When marks is 0
   D. When roll equals 96
   Answer: A. fscanf returns the number of items read; less than 3 means the end of data. (Key point: Reading loop)

3. Which condition selects students to print?
   A. marks > 40
   B. marks >= 40
   C. marks <= 40
   D. marks == 40
   Answer: B. The question asks for 40 marks or more. (Key point: Pass condition)

4. Which fields are printed for the selected students?
   A. Name and marks
   B. Roll number and name
   C. Only marks
   D. Marks and roll number
   Answer: B. The program prints the roll number and the name. (Key point: Output fields)

## Related in Computer Programming

- [Pass student array; display passed students](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-whole-array-student-info) — Computer Programming, chapter 7
- [Binary file of 48 students; highest mark](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-binary-48-students-highest) — Computer Programming, chapter 10
- [RECORD.txt item cost with VAT](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-record-txt-invoice) — Computer Programming, chapter 10
- [Store 48 students in file with append](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-48-students-append) — Computer Programming, chapter 10
- [Read records until end; show nth record](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-worker-nth-record) — Computer Programming, chapter 10, asked 2×
- [Student records with two functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-student-read-display-functions) — Computer Programming, chapter 8

## Related in other subjects

- [Student file read/write and modify by roll](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astudent-file-modify-roll) — Object Oriented Programming, chapter 8
- [File stream; student binary file program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afile-stream-student-binary) — Object Oriented Programming, chapter 8
- [Normal: IOE marks of 5000 students](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Anormal-5000-students-marks) — Probability and Statistics, chapter 3
- [Student file displayed in descending marks order](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astudent-file-descending) — Object Oriented Programming, chapter 8
