orangeboy443
December 11th, 2005, 05:50 PM
Hey, I'm using C language and I want to tell you my code for a function that needs to convert lowercase to uppercase:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
void convertL(FILE *fileName)
{
ClearScreen();
char name[15];
char *p;
printf("\nOption #3\n\n");
fflush(stdin);
printf("Enter a file name: ");
fgets(name, sizeof(name), stdin);
fileName = fopen("text.dat", "w");
if (fileName == NULL) {
printf("There is an error opening the file.\n");
exit(1);
}
char line [MAX_LINE];
printf("Please enter a line of text:, max %d characters\n", sizeof(line));
if (fgets(line, sizeof(line), stdin) != NULL) {
fprintf(fileName, "%s\n", line);
}
char *o;
printf ("Before conversion: %s\n", line);
for (o = line; *o != '\0'; ++o)
{
*o = toupper(*o);
++o;
}
printf ("After conversion: %s\n", line);
return;
}
My output:
Option #1
Enter a file name: name
Please enter a line of text:, max 80 characters
hello there
Before conversion: hello there
After conversion: HeLlO ThErE
Why isnt it making the whole entire text uppercase? It seems like it is skipping characters. What should I change/modify in my code to make it all uppercase??
Thanks
Orange
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
void convertL(FILE *fileName)
{
ClearScreen();
char name[15];
char *p;
printf("\nOption #3\n\n");
fflush(stdin);
printf("Enter a file name: ");
fgets(name, sizeof(name), stdin);
fileName = fopen("text.dat", "w");
if (fileName == NULL) {
printf("There is an error opening the file.\n");
exit(1);
}
char line [MAX_LINE];
printf("Please enter a line of text:, max %d characters\n", sizeof(line));
if (fgets(line, sizeof(line), stdin) != NULL) {
fprintf(fileName, "%s\n", line);
}
char *o;
printf ("Before conversion: %s\n", line);
for (o = line; *o != '\0'; ++o)
{
*o = toupper(*o);
++o;
}
printf ("After conversion: %s\n", line);
return;
}
My output:
Option #1
Enter a file name: name
Please enter a line of text:, max 80 characters
hello there
Before conversion: hello there
After conversion: HeLlO ThErE
Why isnt it making the whole entire text uppercase? It seems like it is skipping characters. What should I change/modify in my code to make it all uppercase??
Thanks
Orange