www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/08/16:32:10

From: jromano AT slate DOT Mines DOT EDU (Jean-Luc Romano)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: integer to string
Date: 8 Feb 1998 21:10:37 GMT
Organization: Colorado School of Mines
Lines: 29
Message-ID: <6bl70d$bou$1@herald.Mines.EDU>
References: <34DE1449 DOT 185C AT bellsouth DOT net>
NNTP-Posting-Host: slate.mines.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <34DE1449 DOT 185C AT bellsouth DOT net> you wrote:
: Im tring to insert the num rturned by getpid(unix sytem call) into a
: string. cna someone tell me how to do this if the 
:  int is Mypid and the ptr to the string is *str.

   I think itoa() (the int to ascii function) should do the trick.
You can try the following:

    str = itoa(Mypid);

   You may encounter a problem is Mypid is not a one digit integer.
If this is the case, you will want to make sure *str is a char string 
and try this little nifty code left over from the original C language:

    sprintf(str, "%d", Mypid);

   The sprintf command is just like the printf command, but instead of
printing the output to the screen (stdout), it prints it to a char
string (in this case, str) for later use.

   (Also note that the sprintf function is useful for concatenating
many variables of different types into one character string.)

   Hope this helps.

   Jean-Luc Romano


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019