B
barnetod
I am trying to open a text file designated by the user.
Then I want to change all lower case values to capital letters.
Then write file.
I am stuck and can not change the characters or am not writing
correctly.
Please let me know what I can do to fix this.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXCHAR 250
int main(void)
{
int c; /* for return value of fgetc */
FILE *fp;
char filename[MAXCHAR];
printf("Enter the name of the file to open\n");
fgets(filename, MAXCHAR, stdin);
filename[strlen(filename) - 1] = '\0';
if (!(fp = fopen(filename, "r")))
{
printf("Unable to open %s\n", filename);
exit(EXIT_FAILURE);
}
while((c = fgetc(fp)) != EOF)
{
if(islower((unsigned char)c))
{
c=toupper(c);
}
fclose(fp);
}
printf("The file has been converted to all Capital letters.\n\n\n");
system("Pause");
return 0;
}
Then I want to change all lower case values to capital letters.
Then write file.
I am stuck and can not change the characters or am not writing
correctly.
Please let me know what I can do to fix this.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXCHAR 250
int main(void)
{
int c; /* for return value of fgetc */
FILE *fp;
char filename[MAXCHAR];
printf("Enter the name of the file to open\n");
fgets(filename, MAXCHAR, stdin);
filename[strlen(filename) - 1] = '\0';
if (!(fp = fopen(filename, "r")))
{
printf("Unable to open %s\n", filename);
exit(EXIT_FAILURE);
}
while((c = fgetc(fp)) != EOF)
{
if(islower((unsigned char)c))
{
c=toupper(c);
}
fclose(fp);
}
printf("The file has been converted to all Capital letters.\n\n\n");
system("Pause");
return 0;
}