www.digitalmars.com         C & C++   DMDScript  

c++.command-line - printf

reply Arthur Buse <zathris hotmail.com> writes:
The page for stdio of the Runtime Library Reference, 
http://www.digitalmars.com/rtl/stdio.html#fread 
the "Example for fread" contains the line
   printf ("Data read\n %. 256s", buf);

Is that space between the . and 256 a mistake? Nothing is printed. The
example below also does not print the string. If the space after . is
removed, it works.

(Real email address is zathras at freeuk dot com )


   #include <stdio.h>

   main()
   {
      char buf[]="Hello, world!";
      printf("\nbuf contains: %. 13s", buf);
   }
Jun 17 2002
parent reply Jan Knepper <jan smartsoft.cc> writes:
Arthur Buse wrote:

 The page for stdio of the Runtime Library Reference,
 http://www.digitalmars.com/rtl/stdio.html#fread
 the "Example for fread" contains the line
    printf ("Data read\n %. 256s", buf);

 Is that space between the . and 256 a mistake?

Yes I would think that is a mistake. The format string should be "%256s" Jan
Jun 17 2002
parent reply Arthur Buse <zathris hotmail.com> writes:
On Mon, 17 Jun 2002 13:37:00 -0400, Jan Knepper <jan smartsoft.cc>
wrote:

Arthur Buse wrote:

 The page for stdio of the Runtime Library Reference,
 http://www.digitalmars.com/rtl/stdio.html#fread
 the "Example for fread" contains the line
    printf ("Data read\n %. 256s", buf);

 Is that space between the . and 256 a mistake?

Yes I would think that is a mistake. The format string should be "%256s"

Ah, you are too busy to compile and run. <grin> The buffer is 256 chars and is probably not \0 terminated, just the first 256 chars from some file. "%256s" pads the field with spaces. "%.256s" limits it to 256 chars. Sorry to go on about this, but people like me are trying to learn from the Runtime Library Reference. #include <stdio.h> main() { char buf[]="Hello, world!"; printf("\nfirst 5 chars of buf: %.5s", buf); printf("\nbuf padded to 20 chars: %20s", buf); } Output: first 5 chars of buf: Hello buf padded to 20 chars: Hello, world! Arthur. -- Windows 95 for Dummies, Windows ME for the Clinicaly Insane.
Jun 17 2002
parent "Walter" <walter digitalmars.com> writes:
"Arthur Buse" <zathris hotmail.com> wrote in message
news:qdmsgukdb92rardnidfm57tbl8hcbn1l3q 4ax.com...
 On Mon, 17 Jun 2002 13:37:00 -0400, Jan Knepper <jan smartsoft.cc>
 wrote:

Arthur Buse wrote:

 The page for stdio of the Runtime Library Reference,
 http://www.digitalmars.com/rtl/stdio.html#fread
 the "Example for fread" contains the line
    printf ("Data read\n %. 256s", buf);

 Is that space between the . and 256 a mistake?

Yes I would think that is a mistake. The format string should be "%256s"

Ah, you are too busy to compile and run. <grin>

Actually, the text was translated from pdf format, and the automatic translator inserts random spaces in the output.
Jun 18 2002