View Full Version : Selecting a specific part of a file
01-10-2011, 05:48 PM
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
01-10-2011, 06:13 PM
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.)
01-10-2011, 06:40 PM
An example file looks like apart from the text in the brackets is not there:
(data)Hello this is the files content
I want to put each element into an array so that the data can be processed.
01-10-2011, 06:52 PM
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?
01-10-2011, 06:58 PM
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.
01-11-2011, 12:43 AM
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.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.