Originally Posted by
AdRock
Thanks zalezog
I'm actually getting somewhere.
It does loop through each of the lines but it only outputs the first "token" on each line
This is an example of what i need to get from my file
1.4 0 0.5
2.3 1.7 0.1
0.8 0 0
0.7 1.0 0.2
1.2 1.3 0.5
Is there a way of tweaking the code cos the output is going to be changed later anyway but I need to get the first line into the array pointers [0][0], [0][1],[0][2] etc and the same for the other lines so i can select 2 array pointers and an display the contents
If you want the whole line to be printed ,then replace every call with..
I don't understand,when you say
If you want to store each word in your file(if that's what you mean)
then something like this might help:
//fragment code
string get_content[10][BUFSIZ];
string words_per_line[5];
//if memory isn't your constraint
//if there are 10 lines in your file
//and if there are more than 5 words in your file
int count_line=0;
int count_word=0;
Then update them in your 'while' loop
while(getline(filename, line))
{
for(int i=0;line[i];++i)
str[i]=line[i];
char * pch=NULL;
char str[BUFSIZ]={0} ;
pch = strtok (str," ");
count_word=0;//reset after each line
while (pch!=NULL)
{
get_content[count_line][count_word]=pch;
pch = strtok (NULL, " ");
array_words[count_line]=++count_word;
}
++count_line;
}
and display them using loops whose control variables are