I've been trying to solve this problem without using pointers, only with the basics (I'm a student) but I can't fine the solution.
void ReverseFile() {
FILE *originalM, *fin;
fopen_s(&originalM, "original.txt", "r");
fopen_s(&fin, "inverted.txt", "w");
char arr[100];
for (int i = 0; i < 100 && !feof(originalM); i++)
{
fscanf_s(originalM, "%c ", &arr[i]);
cout << arr[i] ;
}
cout << endl;
fclose(originalM);
for (int i = 0, k = 100; i < 100; i++, k--)
{
arr[k] = arr[i];
cout << arr[k];
}
fclose(fin);}
So far I have this function and one file of text (originalM.txt) which contains chars (with a space in between):
e e a a e e a a e e a a
In the first loop I get each char of the file and save it in the array. The problem comes in the second loop, where I want to reverse them. How can I solve this? I was trying to create a new array and store the chars but that doesn't work. Also I was trying to print it into the new file with this:
fprintf(fin, "%c ", &arr[k]);
I will be grateful for any help.