|
-
April 4th, 2007, 06:27 PM
#1
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?
-
April 4th, 2007, 06:33 PM
#2
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
-
April 5th, 2007, 09:13 AM
#3
Re: Little question about char convertion
thanks for the info.
the error is gone when the initialization is used. in both cases
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|