[chbot] C prinf() %s

Andre Renaud andre at bluewatersys.com
Tue Nov 22 02:32:16 GMT 2011


Hi Jimmy,
Not sure about the printf modifier, but could you just use
char *s = strchr(line, '\n');
if (s) *s = '\0';
printf("%s", line);

It'll truncate your output if you've got more than one line.
If you've just got a string you want to print, you can generally use
fputs(line, stdout);
instead (saves it needlessly parsing your '%s' modifier). Tragically you
can't use puts, as it always puts a \n back on again :)

Regards,
Andre

On 22/11/11 15:19, jimmy allen wrote:
> Hello All
> 
> So here is a problem, I have a char array that is '\n' terminated.
> Using the printf family I want to print the array.The catch is I do
> not want the '\n' to be printed.
> Apparently there is a flag for the the %s formatter that will print a
> char array with out the '\n'.
> 
> I have tried to find it on the net but haven't got far.
> 
> Any help would be great.
> 
> Cheers
> 
> Jimmy
> 
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Web site: http://kiwibots.org
> Meetings 3rd Monday each month at Tait Radio Communications, 175 Roydvale Ave, 6.30pm
> 
> When replying, please edit your Subject line to reflect new content.


-- 
Bluewater Systems - An Aiotec Company

Andre Renaud        		
andre at bluewatersys.com          5 Amuri Park, 404 Barbadoes St
www.bluewatersys.com            PO Box 13 889, Christchurch 8013
www.aiotec.co.nz                New Zealand
Phone: +64 3 3779127            Freecall: Australia 1800 148 751
Fax:   +64 3 3779135            USA 1800 261 2934



More information about the Chchrobotics mailing list