Alex Rivera | Logout

Converting int to string in C

Asked 2011-03-09T07:15:52.583
47

I am using the itoa() function to convert an int into string, but it is giving an error:

undefined reference to `itoa'
collect2: ld returned 1 exit status

What is the reason? Is there some other way to perform this conversion?

c
Edit
Report

1 Answer

0

If you really want to use itoa, you need to include the standard library header.

#include <stdlib.h>

I also believe that if you're on Windows (using MSVC), then itoa is actually _itoa.

See http://msdn.microsoft.com/en-us/library/yakksftt(v=VS.100).aspx

Then again, since you're getting a message from collect2, you're likely running GCC on *nix.

answered 2011-03-09T07:27:50.893

Your Answer