Question about parsing a string from a line

This is a discussion on Question about parsing a string from a line within the C Programming forums, part of the General Programming Boards category; Hi I've looked up the FAQ entry about sscanf but it doesn't quite suit my needs. In my program I ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    31

    Question about parsing a string from a line

    Hi

    I've looked up the FAQ entry about sscanf but it doesn't quite suit my needs. In my program I have some data that is saved to a file in the form of an array of structs. To read this data I planned on saving each struct on a line then parsing the line using sscanf and then copying it into the appropriate struct variables. The problem: A string has to be read in, but the string may or may not have a space in it eg. "York" or "New York". As I understand sscanf would stop reading at the space in "New York" and in the case of my program try to copy the York into an integer. My question is how would I allow for strings that have a space in them, or would holding each bit of data on a separate line be the answer?

    Thanks in advance.
    Last edited by edd1986; 04-23-2005 at 10:16 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    Well you would need some kind of delimiter between fields.
    Comma seems quite a good choice.

    Then look at say strtok()
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    31
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM

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