toupper problem

Hi all!

Can somebody tell me, why this code doesn't work?

1
2
3
4
5
char * CClass::hex2char(char *hexString) {
	for (unsigned int i=0; i<strlen(hexString); i++) {
		hexString[i] = (char) toupper(hexString[i]);
        }


Thx a lot
eule

What is it supposed to do?

What the code does is convert a string to upper case, which I don't think is what the function was intended to do, but the name of the function is somewhat vague.

Hi!
Well I want to convert a char array to uppercase but the run gives me a segmentation fault....

When I change

hexString[i] = (char) toupper(hexString[i]);

to

 
char chr = (char) toupper(hexString[i]);


it works!

thx
How are you calling hex2char() ?

You cannot, for instance, call it with a literal string:

myClass.hex2char( "Hello World" );

as that will segfault.

Topic archived. No new replies allowed.