Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts

    Selecting a specific part of a file

    Hey, I've written a program which writes data to a file, is it possible to select certain parts of the file in C. For example: the file is stored in the format <size><name><data>. Would it be possible to put each of these into a variable / string / array?

    Thanks for any help

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Sure it is possible.

    (Unspecific questions get unspecific answers if you are looking for more implementation details show part of the input file and explain exactly what you want to do with the data.)
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts
    An example file looks like apart from the text in the brackets is not there:
    (size)32(filename)hello.txt
    (data)Hello this is the files content

    I want to put each element into an array so that the data can be processed.

    Thanks

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    There is no space between the 32 and hello.txt?

    And is the data just one line or can it be multiple lines? Is the size referring the number of characters in the data field?
    OracleGuy

  • #5
    Regular Coder
    Join Date
    Mar 2007
    Location
    UK
    Posts
    151
    Thanks
    9
    Thanked 2 Times in 2 Posts
    There could be a space between them if it makes it easier, the data is on multiple lines and yes the size does reference the characters in the data field.

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    The space would make it easier, then you could use strtok to break that line up. Then you can use the size number to read the next N characters into a buffer to get the data.
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •