string input...with white spaces?

This is a discussion on string input...with white spaces? within the C Programming forums, part of the General Programming Boards category; My memory's fuzzy, so if you can just tell me how to input a string, and have C include the ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    8

    Talking string input...with white spaces?

    My memory's fuzzy, so if you can just tell me how to input a string, and have C include the white spaces, I can get on with my project.

    Until then, I'll just fiddle with it with a one word string array.

    If that isn't coherent enough, C usually cuts off string input eg: scanf ("%s", string1); at \0 characters, or white spaces. I'd like to include the white spaces, so that the input Hello World does not get cut off and recorded as Hello.

    Thanks!

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Check the FAQ.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    8

    Talking

    I'd like to do it with scanf, if possible.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I'd like to do it with scanf, if possible.
    Why? scanf is unsafe, if you make it relatively safe it becomes complex, debugging its mysterious problems would cause a Tibetan monk to scream obscenities, and there are far better alternatives that are easier to use. So again, why?

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    8
    I'm not sure...well, could I use 'gets' instead?

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    >I'm not sure...well, could I use 'gets' instead?
    You're going from bad to worse. Please read the FAQ. Or this one on gets. Or this one on scanf. Or the ones they reference.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I'm not sure...well, could I use 'gets' instead?
    You could, but it wouldn't be any better. How about fgets?

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 02:23 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM

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