[Solved] How to cast an int to a char * in C? [duplicate]


This is just not valid code. Even if you resolve the compile-time error, the result will likely be some sort of memory access error at run time. The result will be a pointer to a string that you have no idea where it actually points to. And so you’ll have an error when your program accesses that memory.

I’m going to speculate that what you are really looking for is a function like itoa(). That’s the only way this would make any sense.

Edit

Based on a new comment, I see that you do in fact want a function like itoa(). Simply trying to convert the integer to a string pointer will not do what you want.

char buff[80];

itoa(i, buff, 10);
myfunction(buff);

5

solved How to cast an int to a char * in C? [duplicate]