#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    42
    Rep Power
    12

    Reading Strings with Spaces


    I've having a wierd problem with some code I'm working with in which both the scanf and cin functions are reading input with spaces as two seperate strings rather that as one string that happens to contain characters. Is there anyway I can get around this? Thanks,
    Eric Andres
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,645
    Rep Power
    4248
    Use fgets() or cin.getline() instead.
    Code:
    #define SIZE 80
    char buf[SIZE];
    
    fgets(buf, SIZE, stdin);
    cin.getline(buf, SIZE);
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    42
    Rep Power
    12
    Thanks, I'll try that...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    42
    Rep Power
    12
    Thanks, works like a charm.

IMN logo majestic logo threadwatch logo seochat tools logo