I'm trying to print a string inside a file but in reverse. But the fprintf
doesn't print it into the file.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <iso646.h>
#include <errno.h>
#include <stddef.h>
#define dim 50
int main(int argc, char const *argv[]) {
FILE *fin;
FILE *fout;
char str[dim];
char nomefilein[dim];
char nomefileout[dim];
int i;
printf("Inserisci il nome del file da leggere:\n");
scanf("%s",nomefilein);
printf("Inserisci il nome del file da scrivere:\n");
scanf("%s",nomefileout);
fin=fopen(nomefilein, "r");
fout=fopen(nomefileout, "w");
while (fgets(str, dim, fin)!=NULL) {
printf("%s",str);
for (i = 49; i > 0; i--) {
fprintf(fout, "%s", str[i]);
}
}
fclose(fin);
return 0;
}
Can you help me?