[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