View Single Post
Join Date: Oct 2008
Posts: 44
Reputation: zalezog is an unknown quantity at this point 
Solved Threads: 11
zalezog zalezog is offline Offline
Light Poster

Re: read line of text from file into array

 
0
  #3
Jan 14th, 2009
Though ,not a good approach but the following approach does work.(if your input contains texts which are separated by more than a couple of newlines,expect some unexpected characters in the output)

Inside the while loop
  1. while (getline(filename, line)) //Loop through lines
  2. {
  3. char str[BUFSIZ] ;//BUFSIZ
  4. // already defined in stdio.h
  5.  
  6. for(int i=0;line[i];++i)
  7. str[i]=line[i];
  8.  
  9.  
  10. char * pch=NULL;
  11.  
  12. pch = strtok (str," ");
  13. while (pch!=NULL)
  14. {
  15. printf ("%s\n",pch);
  16. pch = strtok (NULL, " ");
  17. }
  18. }
Last edited by zalezog; Jan 14th, 2009 at 4:13 pm.
Reply With Quote