Little question about char convertion
Hello!
I've been using sprintf to convert a group of integers to a char sequence.
like this:
char st[];
int a=2,b=3;
sprintf(st,"%d and %d",a,b);
cout<<st;
it works good, but when trying to use char *st; instead of the array an error is thrown.
"Error while dumping state (probably corrupted stack)"
if sprintf receives a char * as first argument, shouldn't it work too?
Re: Little question about char convertion
Are you saying you replaced
by You haven't allocated any memory for the variable - you need to do this in both cases. I think you are lucky in the first case.
Try
Code:
char st[25] = {0}; // allow plenty of room
or
Code:
char *st = new char[25];
or better yet use an STL string.
Regards
Alan
Re: Little question about char convertion
thanks for the info.
the error is gone when the initialization is used. in both cases