LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] nice C question...

[ILUG] nice C question...

Paul J Collins sneakums at zork.net
Wed Apr 11 17:03:01 IST 2001


>>>>> "JPL" == John P Looney <john at antefacto.com> writes:

    JPL> Given an array of integers, terminated with zero, what's the
    JPL> easiest way to make a string from it ?

What zero? --------------------------------
                                           v
    JPL>   int nums[]={2,76,1282,28182,1232};
    JPL>   char big_string[255];
    JPL>   char *tmp_ptr;

    JPL>   big_string[0]=0;
    JPL>   tmp_ptr=big_string;

    JPL>   while(*nums++!=0) {
    JPL>       /* start printing into the end of the previous output */
    JPL>       tmp_ptr=+(sprintf(tmp_ptr, "%s.%d",tmp_ptr,name) - 1);
                      ^^

Should be +=.  Only old broken compilers accept =+.

Also, I don't understand why your format is trying to print the
existing string *and* the number.

    JPL>   }
    JPL>   syslog(LOG_INFO, "big string is %s", big_string);

There may be more problems however.

-- 
"Pity has no place at my table."
      -- Dr Hannibal Lecter




More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell