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
|
#include<iostream>
#include<fstream>
#include<string.h>
#include<stdlib.h> // for system pause ...
using namespace std;
int main(){
int datalen;
ifstream ifdata("data.txt");
ifdata.seekg(0, ios::end);
datalen = ifdata.tellg();
ifdata.seekg(0, ios::beg);
char data[datalen], *word;
ifdata.read(data,datalen);
cout << "Starting Program" << endl << endl;
word = strtok(data, " .,\n"); // first strtok
while(word != NULL){ // keep going till strtok returns a NULL pointer
cout << word << endl; // display the word found and enter a new line
word = strtok(NULL, " .,\n"); // place in variable word the next word found in data string
}
// for some reason i want to repeat the process again.
cout << "Repeating Starting Program" << endl << endl;
word = strtok(data, " .,\n"); // i have no clue on what this does now
while(word != NULL){ // keep going till strtok returns a NULL pointer // for some reasons it sops at the begining
cout << word << endl; // display word, sometimes it gives me some random characters
word = strtok(NULL, " .,\n"); // again don't know how this works the second time
}
system("pause"); //yes, yes i know all about system pause please don't argue about that...
return (0);
}
|