P
pradeep
Hello friends:
I know some people here don't like to answer C++ questions, but I
believe this is really about the underlying C code. Anyway I have posted
as well to the other group someone suggested ("comp.lang.c++") just in
case.
I think the problem is that in my C++ class, we were taught to use cin,
cout etc. but now I need to use the primitive C operations printf etc.
and I don't understand exactly how they work.
I'm trying to convert an integer into a string. Here's what I'm trying,
but when I try to output the string returned from the function, I just
get garbage. How should I be using sprintf?
Thanks.
char *App::IntToString(int i) //doesn't really rely on classes
{
char buf[2];
char *out = buf;
sprintf(out, "%d", i);
return out;
}
I know some people here don't like to answer C++ questions, but I
believe this is really about the underlying C code. Anyway I have posted
as well to the other group someone suggested ("comp.lang.c++") just in
case.
I think the problem is that in my C++ class, we were taught to use cin,
cout etc. but now I need to use the primitive C operations printf etc.
and I don't understand exactly how they work.
I'm trying to convert an integer into a string. Here's what I'm trying,
but when I try to output the string returned from the function, I just
get garbage. How should I be using sprintf?
Thanks.
char *App::IntToString(int i) //doesn't really rely on classes
{
char buf[2];
char *out = buf;
sprintf(out, "%d", i);
return out;
}