#include <fstream>
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int main()
{
string GetFileName;
string line;
cout << "System >> Enter file to read: \n";
cout << "User >> ";
cin >> GetFileName;
ifstream filename( GetFileName.c_str() );
if(! filename )
{
cout << "Unable to open file: " << GetFileName << endl;
return EXIT_FAILURE;
}
else
{
//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;
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;
}
filename.close();
}
return EXIT_SUCCESS;
}