To print a space

This is a discussion on To print a space within the C++ Programming forums, part of the General Programming Boards category; i want to print a space in a text file .wat i have opted so far is fprintf (stream,"%c",32), but ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Location
    Qatar
    Posts
    39

    Smile To print a space

    i want to print a space in a text file .wat i have opted so far is
    fprintf (stream,"%c",32),
    but i am not getting the result,am i wrong or is there anyother way,remember i want to print with fprintf option only.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    fprintf (stream,"%c",' ')

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    fputc(' ', stream);
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,799
    Well, since this is the C++ board:
    Code:
    stream << ' ';
    or
    Code:
    stream.put(' ');
    or
    Code:
    stream.write(" ",1);
    ...assuming stream is some ostream derived object.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    @matsp, hk_mp5kpdw he said use fprintf only.

    fprintf(stream, " ");

    :/

  6. #6
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    You know, whitespace is invisible... better put your spectacles on and make sure the cursor didn't move before you panic.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,025
    If you insist on using fprintf then you need to make sure your stream is a FILE* and use C's file funtions (like fopen() and fclose()) with the stream. Look at C tutotials or file IO to learn more.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    If you want to print to the screen, use stdout for the filestream. Or just use printf(s,...), which is the same as fprintf(stdout,s,...).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read space from the file
    By Ken JS in forum C++ Programming
    Replies: 9
    Last Post: 08-05-2007, 03:13 AM
  2. Replies: 0
    Last Post: 03-28-2003, 07:20 AM
  3. print output problem
    By chor in forum C Programming
    Replies: 1
    Last Post: 12-29-2002, 08:45 AM
  4. Replies: 1
    Last Post: 07-31-2002, 11:35 AM
  5. send data to printer and print on paper
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 07-22-2002, 05:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21