Thread: scan a string

  1. #1
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110

    scan a string

    What is wrong? I am trying to read a user input. The input is a street address ex: 401 North Ave.

    I can't get it to scan???

    The street variable is part of a structure that I am using in a linked list.

    printf("enter street address: ");
    fgets(temp,sizeof(temp),stdin);
    sscanf(temp,"%s", pcurrent->street);

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    What is temp defined as?
    What is pcurrent->street as?
    Why use sscanf() (which won't do what you want anyway)?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Your probably getting '401', right? sscanf scans the first item in the string, in this case, the street number. The best way is just to parse the string manually.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>The best way is just to parse the string manually
    ... depending on what's what's wanted. A simple strcpy() might be all that is needed.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Are you kidding, man? Even if I needed the entire string I'd still parse it for good measure!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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. += operator
    By BKurosawa in forum C++ Programming
    Replies: 8
    Last Post: 08-05-2007, 03:58 AM
  3. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM