#include<stdio.
h>
#include<stdlib.h>
//#include<conio.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
char b1[4096];
char b2[4096];
char b3[4096];
ifstream obj;
obj.open("sampletext.txt");
char* curr_buff = b1;
obj.get(curr_buff, 4096, EOF);
int count = 0, c;
int starting = 0;
int ending = 0;
int previousBuffer = 1;
int totalTokensInFile = 0;
int totalTokensInBuffer1 = 0;
while (curr_buff[count] != '\0')
{
ending++;
if (isspace(curr_buff[count]))
{
totalTokensInFile++;
if (curr_buff == b1) {
totalTokensInBuffer1++;
}
cout << "\n";
if (starting < ending)
{
for (c = starting; c < ending; c++)
{
cout << curr_buff[c];
}
}
else {
if (previousBuffer == 1) {
while (b1[starting] != NULL) {
cout << b1[starting];
starting++;
}
for (c = 0; c < ending; c++) {
cout << curr_buff[c];
}
}
else if (previousBuffer == 2) {
while (b2[starting] != NULL) {
cout << b2[starting];
starting++;
}
for (c = 0; c < ending; c++) {
cout << curr_buff[c];
}
}
else if (previousBuffer == 3) {
while (b3[starting] != NULL) {
cout << b3[starting];
starting++;
}
for (c = 0; c < ending; c++) {
cout << curr_buff[c];
}
}
}
cout << "\n";
starting = ending;
}
count++;
if (count > 4094)
{
if (curr_buff == b1)
{
curr_buff = b2;
previousBuffer = 1;
ending = 0;
cout << endl << endl << endl << "buffer changed 1" << endl << endl
<< endl;
}
else if (curr_buff == b2)
{
curr_buff = b3;
previousBuffer = 2;
ending = 0;
cout << endl << endl << endl << "buffer changed 2" << endl << endl
<< endl;
}
else if (curr_buff == b3)
{
curr_buff = b1;
previousBuffer = 3;
ending = 0;
cout << endl << endl << endl << "buffer changed 3" << endl << endl
<< endl;
}
obj.get(curr_buff, 4096, EOF);
count = 0;
}
}
cout << "count is " << count << endl;
cout << "Total Tokens in Buffer 1 Only " << totalTokensInBuffer1 << endl;
cout << "Total Tokens in File " << totalTokensInFile << endl;
return 0;
}