Nerdy
Nerdy

Reputation: 1099

integer to string conversion using itoa()

I need to append \t to an integer of 4 bytes.Initially integer variable is assigned a value and which has to be appended with \t and transmitted .In the receiver side the integer and \t has to be separated. I have used itoa() and atoi() to convert from integer to string and vice-versa. Code:

int integer=10;
char string[5];
itoa(integer,string,10);

I am getting error as undefined reference to 'itoa'. Is there any alternative to do so and how to recover the \t from the integer...Kindly help me in this regard. Thanks in advance

Upvotes: 0

Views: 573

Answers (2)

Jens Gustedt
Jens Gustedt

Reputation: 78953

The C standard function for this is sprintf

Upvotes: 2

Sridhar DD
Sridhar DD

Reputation: 1980

You have to use

char string[5];
int integer= 10;
snprintf(string, 5,"%d",integer);

Because itoa is not part of the standard function which is supported by some compilers..

Upvotes: 3

Related Questions