Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. can scanf retain leading whitespaces

can scanf retain leading whitespaces

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    b rad311
    wrote on last edited by
    #1

    Hello, Can scanf be set to retain leading whitespaces in between words? For example, if the string was " Hello everyone, how are you today? " can scanf grab " Hello" " everyone," " how" " are" " you" " today?" Thanks,

    D _ 2 Replies Last reply
    0
    • B b rad311

      Hello, Can scanf be set to retain leading whitespaces in between words? For example, if the string was " Hello everyone, how are you today? " can scanf grab " Hello" " everyone," " how" " are" " you" " today?" Thanks,

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Only if you wrote your own parser. The other ideas that I mentioned to you would use the space as the delimiter.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      B 1 Reply Last reply
      0
      • B b rad311

        Hello, Can scanf be set to retain leading whitespaces in between words? For example, if the string was " Hello everyone, how are you today? " can scanf grab " Hello" " everyone," " how" " are" " you" " today?" Thanks,

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        You can do this to capture everything till the enter key is hit.

        scanf("%[^\n]", sz);

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        B 1 Reply Last reply
        0
        • D David Crow

          Only if you wrote your own parser. The other ideas that I mentioned to you would use the space as the delimiter.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "Man who follows car will be exhausted." - Confucius

          B Offline
          B Offline
          b rad311
          wrote on last edited by
          #4

          thanks.

          1 Reply Last reply
          0
          • _ _Superman_

            You can do this to capture everything till the enter key is hit.

            scanf("%[^\n]", sz);

            «_Superman_» I love work. It gives me something to do between weekends.
            Microsoft MVP (Visual C++)

            B Offline
            B Offline
            b rad311
            wrote on last edited by
            #5

            thanks .

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups