0% found this document useful (0 votes)
54 views2 pages

S1 FA17-bcs-151

This C++ program reads text from a file called "sampletext.txt" and outputs it tokenised with whitespace characters as delimiters. It uses 3 character buffers (b1, b2, b3) to store portions of the file as it is read in order to handle files larger than the buffer size. It tracks the number of tokens in the first buffer and total number of tokens in the file.

Uploaded by

Zain Ihsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

S1 FA17-bcs-151

This C++ program reads text from a file called "sampletext.txt" and outputs it tokenised with whitespace characters as delimiters. It uses 3 character buffers (b1, b2, b3) to store portions of the file as it is read in order to handle files larger than the buffer size. It tracks the number of tokens in the first buffer and total number of tokens in the file.

Uploaded by

Zain Ihsan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#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;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy