toupper() for strings?

This is a discussion on toupper() for strings? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I searched the board, to no avail. Is there a function which will convert a string of chars to uppercase? ...

  1. #1
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

    toupper() for strings?

    I searched the board, to no avail. Is there a function which will convert a string of chars to uppercase? I tried creating my own function... but i'm pretty sure i'm going about it the wrong way...

    I tried using a subscript on the pszText variable, but seeing as i'm using a refrence, it doesn't work, and I don't want to return a pointer to a character array either. Here's my messed up code

    Code:
    void MakeStringUpper(char &pszText)
    {
    	for (int i = 0; i <= strlen((char *)pszText); i++)
    	{
    		strcat(&pszText + (sizeof(char) * i), toupper(&pszText + (sizeof(char) * i)));
    	}
    	return;
    }

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    PHP Code:
    #include <stdio.h>

    int main() {
      
    char hemp[30] = "this is A TEST";
      
    toUpperString(hemp);
      
    printf("%s",hemp);


    }

    void toUpperString (char temp) {
      while (*
    temp) {
        if (
    islower(*temp)) *temp toupper(*temp);
        
    temp++;

    }


    return;

    compiled and tested.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    there is a function in string.h to do it:

    char *strupr(char *s);
    My Website

    "Circular logic is good because it is."

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by DavidP
    there is a function in string.h to do it:

    char *strupr(char *s);
    There might be in your compiler, but I don't believe it's in the ANSI standard, so not everyone will have it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. toupper() function
    By strokebow in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2008, 10:54 AM
  2. toupper Function Problems!
    By Dilmerv in forum C++ Programming
    Replies: 6
    Last Post: 04-05-2006, 01:40 PM
  3. need example of toupper()
    By Waldo2k2 in forum C++ Programming
    Replies: 8
    Last Post: 06-29-2002, 10:07 AM
  4. conio.h, toupper(), and a craps game
    By loki221 in forum C Programming
    Replies: 2
    Last Post: 11-28-2001, 06:40 PM
  5. implicit declatation of function 'int toupper(...)'
    By Intimd8r in forum C Programming
    Replies: 3
    Last Post: 10-01-2001, 02:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21