Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用c语言从txt文件中读取数据_C - Fatal编程技术网

用c语言从txt文件中读取数据

用c语言从txt文件中读取数据,c,C,准备一个名为“notes.txt”的文件,其中包含学生姓名、签证和期末成绩。后来 以结构形式阅读文件中的姓名、签证和最终注释。普通签证占40%,期末签证占60% 计算等级。最后,一般成绩为60分及以上的学生将在屏幕上显示其学生姓名和一般成绩。 打印Gecti.txt文件,60岁以下的学生在屏幕上显示学生姓名和一般成绩,以及kaldi.txt文件。 程序运行时,示例文件内容和屏幕截图如下所示。对于notes.txt文件 您可以使用以下数据,程序运行时应自动创建Gecti.txt和Kaldi.txt

准备一个名为“notes.txt”的文件,其中包含学生姓名、签证和期末成绩。后来 以结构形式阅读文件中的姓名、签证和最终注释。普通签证占40%,期末签证占60% 计算等级。最后,一般成绩为60分及以上的学生将在屏幕上显示其学生姓名和一般成绩。 打印Gecti.txt文件,60岁以下的学生在屏幕上显示学生姓名和一般成绩,以及kaldi.txt文件。 程序运行时,示例文件内容和屏幕截图如下所示。对于notes.txt文件 您可以使用以下数据,程序运行时应自动创建Gecti.txt和Kaldi.txt文件。这就是我想做的。但我不知道从txt文件中读取数据

在notes.txt中:

Ali 50 40
Ayse 20 90
Omer 70 80
Elif 50 50
Ahmet 50 80
但我不知道如何读取txt文件中的姓名、签证和最终版本,我也不会写代码。请帮助我

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

}ogr[10];

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

}

ı可以写这篇文章

为了实现这一点,您需要做以下几件事:

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

关于如何读取文件以及如何格式化包含分隔符的字符串,可以在internet和本网站上找到大量示例。

你能展示一下你已经尝试过的内容吗?实际上,你什么都写不出来