-
July 20th, 2009, 11:50 PM
#1
how to convert integer to string in C?
Hi,
I am facing problem in converting integer to string in C programming?Iam using Code composer Studio IDE for debugging the program.There not accepting itoa() function for string conversion.Please tell me some other method for intger to string conversion.Any body please help me.
Thanks
-
July 21st, 2009, 12:46 AM
#2
Re: how to convert integer to string in C?
A example to illustrate:
Code:
#include <stdlib.h> // for itoa() call
#include <stdio.h> // for printf() call
int main() {
int num = 123;
char buf[5];
// convert 123 to string [buf]
itoa(num, buf, 10);
// print our string
printf("%s\n", buf);
return 0;
}
Little by little one goes far
Keep moving.......!
Nothing is impossible !
-
July 21st, 2009, 01:08 AM
#3
Re: how to convert integer to string in C?
Originally Posted by sunny_sz
A example to illustrate:
Except that itoa is non-standard, and sudha_sakthi explicitly noted that it was not available.
Originally Posted by sudha_sakthi
Iam using Code composer Studio IDE for debugging the program.
With a Microsoft compiler? Note that you posted this thread in the Visual C++ Programming forum.
Originally Posted by sudha_sakthi
Please tell me some other method for intger to string conversion.
One way is to use sprintf() with a sufficiently large buffer. To modify sunny_sz's example:
Code:
#include <stdio.h>
int main(void)
{
int num = 123;
char buf[12];
sprintf(buf, "%d", num);
printf("%s\n", buf);
return 0;
}
-
July 21st, 2009, 02:05 AM
#4
Re: how to convert integer to string in C?
With a Microsoft compiler? Note that you posted this thread in the Visual C++ Programming forum.
That means that he is in the right place.
Except that itoa is non-standard, and sudha_sakthi explicitly noted that it was not available.
Explicitly ? And he said that because it was non-standard ? I guess I need reading glasses....
There not accepting itoa() function for string conversion.
Why not ? The whole world uses it ...
-
July 21st, 2009, 02:30 AM
#5
Re: how to convert integer to string in C?
Originally Posted by Skizmo
That means that he is in the right place.
If the answer is yes, that is. The Code Composer Studio IDE appears to come with a compiler from Texas Instruments rather than Microsoft.
Originally Posted by Skizmo
Explicitly ? And he said that because it was non-standard ? I guess I need reading glasses....
Yes, you do I stated that it was non-standard. sudha_sakthi stated that it was "not accepting itoa() function for string conversion". Granted, I might have misinterpreted the statement, but since it is non-standard, it is reasonable to suppose that "not accepting" was due to "unavailable", considering that I already suspect that the compiler is from Texas Instruments.
-
July 21st, 2009, 03:45 AM
#6
Re: how to convert integer to string in C?
Hi all,
yes. the code composer IDE is from Texas Instrument .Using sprintf() function it is working fine.
Thank u....
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
|