Problem with strtok

This keeps printing out the last string read starting at the beginning of the string lineIn and ending were the string was parsed.

This is the last string read "put something< in the middle"
The out put looks like this:

put something
 in the middle
put something


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
  FILE * pFileIn;
  FILE * pFileOut;
  char lineIn[2001];
  char lineOut[2001]= "z";
  char * ptr1, * ptr2;
  int c;
  int n=0, i=0;

  pFileIn = fopen ("c:\\PointsOfInterest\\readfile.txt","r");
  

  if (pFileIn!=NULL) //if the file opened
  {
     do 	{
		fgets (lineIn,2000,pFileIn);		//get the next string from the file
		ptr2 = strtok (lineIn,"><");		//find the sub string in the lineIn string
			
		while (ptr2 != NULL){			//step through the string{
		cout << ptr2  << endl;			//print the string
		ptr2 = strtok (NULL,"><");		//must send back NULL for strtok to look for next occurance
		}
			
	} while ( ! feof(pFileIn));
	fclose (pFileIn);
	
  } //end if
  return 0;
}
Topic archived. No new replies allowed.