I'm having trouble taking a string, fed from a text file, and changing that string into an array of strings.
My goal is, everytime i hit a '\n' in the string, it creates another string in the string array.
I'm doing this because I'm trying to break a text file down, and be able to reference each one of its lines individually.
For example, if i had a text file, as follows, and I read the whole thing into one (1) string,
It seems today
That all you see
Is violence in movies
And sex on tv
and I wanted to print line 3 I'd just do
Code:
printf("%s", linearray[2]);
Hopefully the follow code will give you a good idea of what I'm trying to accomplish, and maybe you can help me figure out why i cant get it to work.
Code:
for (x = 0, y = 0, z = 0; buffer[x] != EOF; x++)
{
if (buffer[x] == '\n')
{
y = 0;
z++;
} //end if
else
{
linearray[z][y] = buffer[x];
y++;
} //end else
} //end for loop
I'm pretty sure the error is in my for loop here, if looks ok to all of you, I'll post the whole program so far, and let you analyze it all.
I appreciate your help, everyone has been a big help, and my learning curve would be way down without you.