CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #1
    Join Date
    Dec 2005
    Posts
    63

    Conversion to lower to upper case problem

    Hey, I'm using C language and I want to tell you my code for a function that needs to convert lowercase to uppercase:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <conio.h>


    Code:
    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
    Last edited by orangeboy443; December 11th, 2005 at 07:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured