Good afternoon, Happy holiday to you all. Help solve the following questions:
- How to process the received data from the file
- For example, how to calculate the sum of all numbers in a file and write them to another file.
Here is an example of a program that simply reads from a file and displays them in a dialog box, but does not perform any operations with them.
#include "stdafx.h" // 1. За что отвечает эта библиотека? #include <stdio.h> // Библиотека отвечающая за совместоность с windows. #include <windows.h> int _tmain(int argc, _TCHAR * argv[]) { //Библиотека windos.h SetConsoleCP(1251); SetConsoleOutputCP(1251); //*fp-Выделение памяти и название файла. // fopen - открытие файла, test1.txt название текстового файла файла // "r" - режим (файл открывается только для чтения. FILE *fp = fopen("test1.txt", "r"); //Если такового файла нет, то выдает ошибку, но почему то сразу закрывает программу if (NULL == fp) { printf("Не удалось открыть файл!\n"); return 0; } //Обозначаем переменную str, типа char, [24] кол-во символов которые буду прочитаны. char str[24] = ""; //2. Что такое feof? И почему перед ним воскл. знак while (!feof(fp)) { //3. За что отвечает fgets? fgets(str, 24, fp); printf("%s", str); printf("n"); } //Закрытие файла. fclose(fp); // Не знаю за что отвечает эта ф-ия ( system("pause"); getchar(); getchar(); return 0; }
Since I am a beginner, could you indicate with the help of "//" what you are doing with the help of this operation. Also in the program itself there are not understandable to me f-ii, could you explain them. Thank you all in advance for your help.