Re: how to convert integer to string

From: John Gordon (gordon_at_panix.com)
Date: 09/26/05


Date: Mon, 26 Sep 2005 19:59:24 +0000 (UTC)

In <1127764115.096827.16830@o13g2000cwo.googlegroups.com> "hirenshah.05@gmail.com" <hirenshah.05@gmail.com> writes:

> i tries itoa, but it is not compiling. so please tell me how to convert
> integer to string

itoa() isn't a standard function. Some computers have it, and some don't.
Try sprintf():

  char buffer[99];
  int i = 357;

  sprintf(buffer, "%d", i);
  /* buffer now contains "357" */

-- 
John Gordon            "It's certainly uncontaminated by cheese."
gordon@panix.com


Relevant Pages

  • Re: problem with _XOPEN_SOURCE in OpenBSD 3.4
    ... >> of sprintf unsafe. ... int auto_login{ ... if malloc fail to allocate memory space. ... value provided to login() is set by readline. ...
    (comp.unix.bsd.openbsd.misc)
  • Re: queries about sprintf
    ... > int main{ ... > sprintf returns: 3 ... every ASCII character is essentially an one-byte integer ... "%c" specifier matches an `int' argument, ...
    (comp.std.c)
  • Telnet client in C
    ... int main ... sprintf (buffer, "%c%c%c",255,252,36); ... //sending the username ...
    (comp.lang.c)
  • [Full-disclosure] new class of printf issue: int overflow
    ... I noticed this code because it calls abs on an int. ... Second issue: int overflow in *printf: ... What if sprintf returns a negative value? ...
    (Full-Disclosure)
  • [PATCH 3/5] UML - Locking documentation
    ... Some locking documentation and a cleanup. ... into a local before sprintf sees it, ... int count, int *eof, void *data) ... Don't register by default -- as this registeres very early in the ...
    (Linux-Kernel)