Hi,
Okay, so what I am actually trying to do is open a file, convert any lowercase text to uppercase, and then print it on screen. I thought it best to first just begin by trying to open a file and display the contents on screen. I figured that once I had accomplished that, I would try to then tackle the uppercase problem.
Well, things aren't working out so well. I have the program, but it keeps displaying the portion that reads, "The file was not opened successfully. Please check that you entered the file name correctly."
I have a text document in the same folder as the cpp file and all of the rest of it, so I can't see what the problem is. I should probably mention that I am not using quotes when I enter the file name. I am just typing document.txt and then pressing enter. Can someone please have a look and tell me where I have gone wrong?
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *inFile;
char fileName[13];
char text;
printf("\nEnter a file name: ");
gets(fileName);
inFile = fopen(fileName, "r"); /*This opens the file */
if (inFile == NULL) /*Checks that the file exists*/
{
printf("\nThe file %s was not opened successfully.", fileName);
printf("\nPlease check that you entered the file name correctly.\n");
exit(1);
}
while (fscanf(inFile, "%s", text) !=EOF) /*Reads and displays the file*/
printf("%s\n", text);
fclose(inFile);
return 0;