Path: chuka.playstation.co.uk!news From: "Matt Verran" Newsgroups: scee.yaroze.beginners Subject: Re: integer to string Date: Sun, 27 Jun 1999 13:25:12 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 39 Message-ID: <7l55bp$1117@chuka.playstation.co.uk> References: <7l2qan$qpv24@chuka.playstation.co.uk> NNTP-Posting-Host: modem-92.name14.dialup.pol.co.uk X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Brilliant, this looks like what I wanted, I knew there had to be a simple solution. Thanks Toby and Rikki Toby Sargeant wrote in message ... >On Sat, 26 Jun 1999 16:04:48 +0100, Matt Verran wrote: >>Hi, >> >> How to I convert an integer (int) to a string (*char)? I know that to >>convert a single digit to a char you can add 48, but i'm having trouble >>making a string. >> >>cheers//matt >> >> >sprintf (str,"%d",val); > >or if you want a function to do it: > >char *int_to_str(char *buf,int val) { > static char temp[32]; > char *t=temp+31; > > temp[31]=0; > if (!val) { > *--t='0'; > } else { > while (val) { > *--t='0'+(val%10); > val/=10; > } > } > return strcpy(buf,t); >}