The task is as follows.
Open a file containing ten numbers, read them and show them in the dialogue. Create a new file, and write to it the sum of these numbers.
The question is this:
- How to read numbers from a file for further operations with them.
- How to write to a file
That's what I did (incomplete version of the program, but working)
#include "stdafx.h" #include <stdio.h> #include <windows.h> int _tmain(int argc, _TCHAR * argv[]) { SetConsoleCP(1251); SetConsoleOutputCP(1251); FILE *fp = fopen("test1.txt", "r"); if (NULL == fp) { printf("Не удалось открыть файл!n"); return 0; } char str[24] = ""; while (!feof(fp)) { fgets(str, 24, fp); printf("%s", str); printf("n"); } fclose(fp); system("pause"); getchar(); return 0; }
PS already tortured with this VisualStudio C ++: there is no information and examples of tasks, and if there is, then there are so incomprehensible characters that you can break your head.