Path: chuka.playstation.co.uk!tjs From: tjs@cs.monash.edu.au (Toby Sargeant) Newsgroups: scee.yaroze.beginners Subject: Re: integer to string Date: 27 Jun 1999 00:08:42 GMT Organization: PlayStation Net Yaroze (SCEE) Lines: 29 Message-ID: References: <7l2qan$qpv24@chuka.playstation.co.uk> NNTP-Posting-Host: longford.cs.monash.edu.au X-Newsreader: slrn (0.9.4.3 UNIX) 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); }