Good afternoon, Happy holiday to you all. Help solve the following questions:

  1. How to process the received data from the file
  2. 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.

  • one
    It doesn't cost anything to explain, because knowledge is simply zero. We take a good book on C ++ and persistently study. - skegg
  • Tomorrow by 10 am I need to hand it over or leave the sabbatical leave - ek8800
  • Better vacation than lousy specialists. - skegg
  • Why are you so serious then. I ask a lot unless? If FILE * fp = fopen is reading from a file, then how will the file be written to. I do not think that there are very different operators. - ek8800 2:22 pm
  • @ ek8800, there is such a command - man. It’s better to read man fopen, man feof, man fgets, etc., than to ask primitive questions and bicker with the respondent. Immediately I say, at the end of each man there is a section "SEE ALSO". Highly recommend. If you are working in the view, then you can read the man-s on the Internet, for example, here But if after that there are specific questions, then you are welcome, ask. - avp

1 answer 1

  • feof - check for the end of the faly, the exclamation mark is a logical NOT
  • fgets - if I'm not mistaken, returns data from a file
  • system - I provide a description from some portal

The system function passes the specified string to the command interpreter and processes this string as an MS DOS command. The system function refers to the COMSPEC and PATH environment variables to locate the COMMAND.COM file that is used when executing the string command.

  • one
    1. fgets - not just returns the data, but reads the C string from a file and writes to the specified buffer, but not more than the number of characters specified in the second argument. The end of line character is also recorded. 2. The system accepts the C string as an argument and executes it in the standard system interpreter. In DOS, this is the DOS command line; in Nix, the command interpreter of the user on whose behalf the program is launched. - skegg