scan a string

This is a discussion on scan a string within the C Programming forums, part of the General Programming Boards category; What is wrong? I am trying to read a user input. The input is a street address ex: 401 North ...

  1. #1
    Max
    Max is offline
    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,655
    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.

  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,655
    Are you kidding, man? Even if I needed the entire string I'd still parse it for good measure!

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, 11:47 AM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM

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