The code is working nice for me.
But feel free to give me advice.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100
int main(int argc, char** argv) {
FILE *pFile;
FILE *pFileOut;
char string[SIZE];
// Opening the file on reading mode and see if is valid.
if ((pFile = fopen("code.txt", "rt")) == NULL) {
printf("%d %s\n", errno, strerror(errno));
return -1;
}
// Opening the file in writing mode and see if is valid.
if ((pFileOut = fopen("new.txt", "wt")) == NULL) {
printf("%d %s\n", errno, strerror(errno));
fclose(pFile);
return -1;
}
while (!feof(pFile)) { // feof returns 0 until it reach the end of the file. - !feof
fgets(string, SIZE, pFile); // Going line by line, MAX SIZE, From where.
if (fprintf(pFileOut, "%s", string) < 0) {
printf("fprint got some error");
fclose(pFileOut);
fclose(pFile);
return -1;
}
}
fclose(pFileOut);
fclose(pFile);
return (EXIT_SUCCESS);
}