PDA

View Full Version : toupper() for strings?



Dual-Catfish
06-04-2002, 02:07 PM
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



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

ygfperson
06-04-2002, 02:21 PM
#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.

DavidP
06-04-2002, 02:28 PM
there is a function in string.h to do it:

char *strupr(char *s);

Hammer
06-04-2002, 05:24 PM
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.