heres the whole code......the eof while statement takes place in the input function
Code:
#include <iostream>
#include <fstream>
#include <stddef.h>
#include <stdlib.h>
#include <ctype.h>
#include <string>
using namespace std;
struct StackFrame
{
string data;
StackFrame *link;
};
typedef StackFrame* StackFramePtr;
class search
{
public:
bool check(); //declare the function check
void output(StackFramePtr top); //declare the function output
void input(search sight, char *file);
void input2(search sight, char *file, StackFramePtr top);
int a;
int b;
int total3;
private:
int total;//variable for total number of strings
int total2;//variable for number of characters in temp array
int i;//variable for number of strings in array
int j;//variable for number of characters in a string
int m;//variable for number of characters in temp string
int n;//variable for the insert loop
int s;//variable for ?
ifstream in_stream; //create an instream
ofstream out_stream;//creat an outstream
char array[1000][30];//create an array
char temp[1000][30];//create an array
char next;//variable for next character in
};
int main()
{
char *name;
search sight1;
sight1.a = 0;
sight1.b = 0;
sight1.total3 = 0;
StackFramePtr top;
top = new StackFrame;
for(int h = 0; h < 1; h++)
{
if(h == 0)
{
name = "text1.txt";
sight1.input(sight1, name);
sight1.input2(sight1, name, top);
}
if(h == 1)
{
name = "adams.txt";
sight1.input(sight1, name);
sight1.input2(sight1, name, top);
}
if(h == 2)
{
name = "jefferson.txt";
sight1.input(sight1, name);
sight1.input2(sight1, name, top);
}
if(h == 3)
{
name = "madison.txt";
sight1.input(sight1, name);
sight1.input2(sight1, name, top);
}
}
sight1.output(top);
cout << " " << sight1.total3;
return 0;
}
void search::input(search sight, char *file)
{
for(s = 0; s < 1000; s++)
{
for(m = 0; m < 30; m++)
temp[s][m] = 'c';
}
for(i = 0; i < 1000; i++)
{
for(j = 0; j < 30; j++)
array[i][j] = 'd';
}
s = 0;
m = 0;
total2 = 0;
total = 0;
i = 0;
j = 0;
in_stream.open(file);
in_stream.get(next);
while(! in_stream.eof())//while next is not end of file
{
//invariant: next is not the end of the file and next is a part of the file
if(ispunct(next))
{
in_stream.get(next);
}
if(isspace(next))//if next is space
{
in_stream.get(next);/*//get next character from file
array[i][j] = '\0';//put null to end current string
j = 0;//bring number of characters back to zero
i++;//start a new string
total++;//add one to total number of strings*/
}
else//if next is not a space
{
while(isalnum(next))
//invariant: next is either a letter or a number and next is a part of the file
{
temp[s][m] = tolower(next);//put next into temp array
m++;//go to next place in temp array
total2++;//add one to total number of temp characters in temp string
in_stream.get(next);//get next character from file
}
temp[s][m] = '\0';
m = 0;//bring back to first character in temp string
if(check())//if temp string already in array
{
in_stream.get(next);//get next character from file
s++;
}
else//if temp string not already in array
{
for(n = 0; n < total2; n++)//for every character in temp array
//invariant: n is less than total2 and has a place in the array
{
array[i][j] = temp[s][n];//add temp character to current place in array
j++;//go to next place in current array
}
array[i][j] = '\0';
in_stream.get(next);//get next character from file
i++;//start a new string
total++;//add one to total number of strings
total2 = 0;//reset number of characters in temp string back to zero
s++;
if(! in_stream.eof())
j = 0;
}
}
}
in_stream.close();
}
void search::output(StackFramePtr top)
{
while(top != NULL)
{
string result;
result = top->data;
StackFramePtr temp;
temp = top;
top = top->link;
delete temp;
cout << result;
}
}
bool search::check()//function defenition
{
int sum = 0;//represents sum of coorect letters
int answer = 0;
int numstring;//represents string of array
int x;
int l = 0;
int f = 0;
int totalchar;
if(total == 0)
return false;
for(numstring = 0; numstring < total; numstring++)//loops through all strings in array
//invariant: numstring is less than c and a[numstring][f] is part of an array
{
totalchar = 0;
for(f = 0; array[numstring][f] != '\0'; f++)
//invariant: a[numstring[f] does not equal a null character and a[numstring][f] is part of an array
{
if(isalnum(array[numstring][f]))
totalchar++;
}
l = 0;
sum = 0;
x = 0;
while((array[numstring][l] != '\0') || (temp[s][x] != '\0'))
// a[numstring][l] and b[t][x] are both not null characters and they are both parts of arrays
{
if(array[numstring][l] == temp[s][x])
{
sum++;
if(temp[s][x] != '\0')
x++;
if(array[numstring][l] != '\0')
l++;
}
else
{
if(temp[s][x] != '\0')
x++;
if(array[numstring][l] != '\0')
l++;
}
if((sum == total2) && (x == l) && (totalchar == sum))
answer = 1;
}
}
if(answer == 1)
return(true);
else
return(false);
}
void search::input2(search sight, char *file, StackFramePtr top)
{
int j;
j = 0;/*
array[i][j] = '?';//add a question mark to current place in array to signal end of array
i = 0;//reset current string to first string
j = 0;//reset current character to first character
top = new StackFrame;
top->data = array[i];
top->link = NULL;
i++;
while(array[i][j] != '?')//while not end of array
//invariant: array[i][j] is not a question mark and array[i][j] is part of an array
{
StackFramePtr temp;
temp = new StackFrame;
temp->data = array[i];
i++;
temp->link = top;
top = temp;
}*/
}