Thread: C++ newbie..convert string from lowercase to uppercase

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    Question C++ newbie..convert string from lowercase to uppercase

    i am wrting a small function that takes a string in lowercase then i want to change it to uppercase. How do i do that?

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    Take a look at the standard function toupper();

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    Code:
    int stringtoupper(char *str)
    {
     while(*str)
     {
      *str = toupper(*str);
      *str++;
     }
     return 0;
    }
    try that
    usage:
    Code:
    stringtoupper(str);

  4. #4
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    dont forget to
    Code:
    #include <ctype.h>
    example:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    int stringtoupper(char *str)
    {
     while(*str)
     {
      *str = toupper(*str);
      *str++;
     }
     return 0;
    }
    
    
    int main(int argc, char *argv[])
    {
      char s[] = "hElLo";
      stringtoupper(s);
      printf("%s\n",s);
      system("PAUSE");
      return 0;
    }
    Last edited by Brian; 02-25-2002 at 04:11 PM.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    *str++;

    should be .....

    str++;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    strupr(str), strlwr(str) will perform full string upper/lower conversion without the increment char by char thing.

    its' in ctype or string.h
    -

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  4. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 09:19 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM