1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
char NF[100] {};
cout << "Enter file name = ";
cin >> NF;
strcat(NF, ".step"); // a random extension to the file.
//FILE* fp = fopen("C:\\LPS2025ro.txt", "w+"); // my purpose was to save it to disk C
FILE* fp = fopen(NF, "w");
if (fp == NULL) {
cout << "Error W " << endl;
return 1;
}
cout << "OK w " << endl;
char n[100] {}, p[100] {}, g[100] {};
cout << "Enter name::";
cin >> n;
cout << "Enter surname::";
cin >> p;
cout << "Enter group::";
cin >> g;
for (int i = 0; i < strlen(n); i++)
fputc(n[i], fp);
fputc('\n', fp);
for (int i = 0; i < strlen(p); i++)
fputc(p[i], fp);
fputc('\n', fp);
for (int i = 0; i < strlen(g); i++)
fputc(g[i], fp);
fputc('\n', fp);
fclose(fp);
fp = fopen(NF, "r");
if (fp == NULL) {
cout << "Error R " << endl;
return 2;
}
cout << "OK R " << endl;
char nn[100] {}, pp[100] {}, gg[100] {};
for (int n = 0, c; (c = fgetc(fp)) != EOF && c != '\n'; nn[n++] = c);
for (int n = 0, c; (c = fgetc(fp)) != EOF && c != '\n'; pp[n++] = c);
for (int n = 0, c; (c = fgetc(fp)) != EOF && c != '\n'; gg[n++] = c);
cout << "nn: " << nn << '\n';
cout << "pp: " << pp << '\n';
cout << "gg: " << gg << '\n';
fclose(fp);
return 0;
}
|