I have a function that gets a string from the user and then does the following
void TraverseFile(char *inFile, char *outFile)
{
FILE *pIn;
FILE *pOut;
pIn = fopen(inFile, "r");
char c;
if (pIn == NULL)
{
printf("File not found");
}
pOut = fopen(outFile, "w");
if (pOut == NULL)
{
fclose(pIn);
printf("The write file cannot be opened.\n");
exit(1);
}
else{
while(1) //while it is not the end of input file
{
c= putchar(tolower(fgetc(pIn)));
if (feof(pIn)) break;
fputc(c,pOut);
}
fclose(pOut);
}
fclose(pIn);
}
Two things are happening: the while loop is giving me a segmentation fault. I think after input is because fgetc() returns in an int and I want to convert to a char. And the creation of the second file has a weird dot next to the txt name (see picture).