Here is an example written in java that will read a string from a file and return an array of strings. It should be easy to adapt it to C /C++.
Code:
import java.net.*;
import java.io.*;
public class ParsingStreamReader
{
BufferedReader file;
public ParsingStreamReader(InputStream in)
{
file= new BufferedReader(new InputStreamReader(in));
}
public String readLine()
{
try
{
return file.readLine();
}
catch(Exception e)
{
return null;
}
}
public String[] parseLine()
{
String ps[]=new String[0];
String str;
String tmp[]=null;
int front=0,end=0;
try
{
str=file.readLine();
}
catch(Exception e)
{
return null;
}
if(str==null)return null;
str=str.trim(); //Remove white space from the front and back of the string.
if(str.length()==0)return ps;
while((str.charAt(end)>' ')&&(end<str.length()-1))end++;
while(true)
{
tmp=ps;
ps=new String[ps.length+1];
for(int x=0;x<tmp.length;x++) ps[x]=tmp[x];
ps[ps.length-1]=str.substring(front, end);
if(end>=str.length()-1)break;
if(end<str.length()-2)
while((str.charAt(end+1)<=' ')&&(end<str.length()-1))end++;
front=end+1;
end=front;
if(end<=str.length()-1)
while((str.charAt(end)>' ')&&(end<str.length()-1))end++;
if(end==str.length()-1)end=str.length();
}
return ps;
}
}