🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #1508

Re: Printf: vaste lengte strings en ints?

#1508
From: Dr.Ruud
Date: Wed, 02 Mar 2005 22:31
44 lines
2376 bytes
Wat moi schreef, bleek het
begin  van iets moois; kijk zelf maar:

> Ik denk dat:
>
> char buff[ 30+ 3 *INT2POS(int) + 2 * FLOAT2POS(double) +1];
> sprintf(buff, "%d %d : %d : dubbele vlootjes: [%lf %lf %lf %lf]\n"
>   ,a,b,c, f1,f2,f3,f4);
>
> ... een veel lastiger soort probleem kan veroorzaken dan
>
> char buff[512] ;
> printf(buff, "%d %d : %d : dubbele vlootjes: [%lf %lf %lf %lf]\n"
>   ,a,b,c, f1,f2,f3,f4);

Bedoel je die '2 *' terwijl je 4 long floats wilt weergeven?
Of die 30 die >=32 moet zijn?
Een FLOAT2POS is trouwens wat lastiger te maken.


Ik heb de preciese syntax niet gecontroleerd, maar zoiets kan dacht ik
ook:

  const char fmt = "%d %d : %d : dubbele vlootjes: [%lf %lf %lf %lf]\n";
  char buff[ sizeof(fmt[]) + 3 * INT2POS(int) + 4 * FLOAT2POS(double)
+1];
  sprintf(buff, fmt, a,b,c, f1,f2,f3,f4);


Ik denk dat het '%Lf' is en de 'l' alleen voor integer-formats mag
staan.
Of %lf is double, en %Lf long double, dat kan ook nog.


> En, nogmaals: als je het echt zeker wilt weten, is vsnprintf() je
> vriendje.

Ja, dat is beter.

-- 
Affijn, Ruud   `  -  �
               + ` � *
                 � `     Jvr qvg yrrfg,
               �  =  `   fgresg wbatre.
Technical Details
Message-ID: <d05ins.l8.1@news.isolution.nl>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.newsland.it!humbolt.nl.linux.org!news.nl.linux.org!transit.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
References: <M5qdnYvpZutbs7nfRVnyjA@scarlet.biz> <d01i4u.14c.1@news.isolution.nl> <CqudnXnc_MjnCbjfRVnyhg@casema.nl> <d050po.130.1@news.isolution.nl> <FMSdnW58LdbOtrvfRVnyvQ@casema.nl>

Show Full Headers
Complete Article Headers
X-Google-Thread: fcea4,f962124bbb04ff22
X-Google-Thread: 107324,f962124bbb04ff22
X-Google-Attributes: gidfcea4,gid107324,public
X-Google-Language: DUTCH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.newsland.it!humbolt.nl.linux.org!news.nl.linux.org!transit.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Message-ID: <d05ins.l8.1@news.isolution.nl>
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Newsgroups: be.comp.programming,nl.comp.programmeren
References: <M5qdnYvpZutbs7nfRVnyjA@scarlet.biz> <d01i4u.14c.1@news.isolution.nl> <CqudnXnc_MjnCbjfRVnyhg@casema.nl> <d050po.130.1@news.isolution.nl> <FMSdnW58LdbOtrvfRVnyvQ@casema.nl>
Subject: Re: Printf: vaste lengte strings en ints?
Date: Wed, 2 Mar 2005 23:31:31 +0100
Organization: Chaos rules.
X-Newsreader: WMDIYB
X-Archive-Me: please
Approved: yesterday
X-Face: &CQ$FIr!=+=w,8`0Q^Ug"1>F[(/op8->E;NQet`5fe$;=e*!Z5&REvp<~Tj|"Y[|8OcJ{w#z&mB7B:I)XO*%_|\]|YW$C>>$Q[9-#K~c$tQ^Mf0,wMo?h\C)TE>f
Lines: 46
NNTP-Posting-Host: 194.109.164.102
X-Trace: 1109803207 news.xs4all.nl 43106 [::ffff:194.109.164.102]:34714
X-Complaints-To: abuse@xs4all.nl