简体   繁体   中英

Reading data from txt file in c language

Prepare a file called “notes.txt” which contains students' names, visa and final grades. Later read the names, visa and final notes in the file in a structure. General with 40% of the visa and 60% of the final Calculate the grade. Finally, students whose general grade is 60 and above are displayed on the screen with their student name and general grade. Print the "Gecti.txt" file, the ones below 60 with the student name and general grade on the screen and the "kaldi.txt" file. When the program runs, sample file contents and screenshot will be as follows. For the "notes.txt" file You can use the following data, "Gecti.txt" and "Kaldi.txt" files should be created automatically when the program is run. This is what i want to do. But I dont know read a data from txt file.

In notes.txt:

Ali 50 40
Ayse 20 90
Omer 70 80
Elif 50 50
Ahmet 50 80

but I don't know how can read name and visa and final in txt file and I can't write code.pls help me

 #include <stdio.h>
struct ogrenci
{
    char isim[30];
    int vize;
    int final;

}ogr[10];

int main()
{
    FILE * notlar = fopen("notlar.txt","r");

}

ı can write just this

In order to achieve this, there are the following things you need to do:

Open the file for reading (this part you have done)
Start a loop (until end-of-file is reached), and inside that loop:
  Read a line from the file
  Format the line (using the space character as a separator) in order to find the three different kinds of information.
  Add the mentioned information in the structure you have created.
  Put the mentioned structure in a collection.
Close the file

About how to read files and how to format strings, containing separators, there are plenty of examples to be found on the internet and on this site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM