views:

138

answers:

2

Hi,

I'm passing as input to my program: "<param value=s/>"

I use this code:

char character[1];
sscanf(data, "<param value=%c/>", &character);
printf("%c", character);

However the output seems to be "s/>" instead of only "s" char. what's wrong here?

A: 

Your code is correct, but you need to output character[0]:

printf("%c", character[0]);

You should drop the address operator in front of character, though, as sscanf() expects an argument of type char * and not char (*)[1]:

sscanf(data, "<param value=%c/>", character);
Christoph
Thanks! That worked perfectly!
goe
A: 

char character[1] could be replaced by char character, fixing your bug at the same time.

If you want to keep character as an array, you must use &character[0] or character as sscanf argument, and character[0] as printf argument.

Pierre Bourdon
goe
You have one character. Why are you trying to split it up?
Pete Kirkham