CJ wrote:
Newbie here.
Trying to tackle following:
Read text file containing list of files delimited by end of line
chars.
I'm going to assume this means a '\n' character.
---
Any help would be appreciated.
If your file is in the format of:
Line1\n
Line2\n
Line3\n
each \n being where you hit ENTER, i'd suggest the 'fgets' function.
char * fgets( char * buff, int size, FILE * stream );
One thing i've used often, is gotten the length of the longest line
in the file, then allocated a buffer big enough to hold that line.
That way i could hold /any/ line from the file just fine. The
nice thing about fgets is if it reaches a '\n' character /before/
'size' bytes are read in, it will copy the '\n' into 'buff', and
append a null character ('\0'). So long as you allocated enough
space for 'buff' you should be fine. In my case i had the ease of
knowing no 'users' would randomly change the contents of my file.
If your file names can grow in length at any time i'd suggest some
other way to read up to a '\n'. Could get slightly more complex,
especially if you start getting into reallocating 'buff'. Or if you
have the ability to recompile the code to reflect those name changes,
such as i did, that's another option as well. One thing to be sure you
keep in mind is allocating enough room for the longest string + 1. That
way you'll have enough for fgets to copy that '\n' character over, AND
append the null terminating character. Otherwise it could get ugly.
Just an idea i've used that's worked nicely, hope it helps.
FMorales...