I'm writing a program that asks user to enter a file to be opened and then convert all lower case letters to uppercase letters and then display the file. the way i have my program write now, it doesnt seem to go go into the toUpper function and when it displays the file, my program crashes. Please help, Thank you.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *inFile;
char fileName[30];
char toUpper(char);
printf("\nPlease enter the file to be opened: ");
gets(fileName);
inFile = fopen(fileName, "r");
if (inFile == NULL)
{
printf("\nThe file %s was not successfully opened.", fileName);
printf("\nPlease check that you have typed in the correct file.\n");
system("PAUSE");
exit(1);
}
printf("\nThe file has been opened\n");
system("PAUSE");
void convert(char fileName[])
{
int i=0;
while (fileName[i] != '\0');
{
fileName[i] = toUpper(fileName[i]);
i++;
}
}
while (fscanf(inFile,"%s", fileName) != NULL)
printf("%s", fileName);
system("PAUSE");
return 0;
}
char toUpper(char letter)
{
if( letter>= 'a' && letter <= 'z')
return (letter - 'a' +'A');
else
return (letter);
}