wondering if anyone could help, i have a program that is supposed to take in characters from a text file and store them in a two demensional array so that i can store them as words. i use a while loop using the isalnum function to store them. this while loop using the isalnum function seems to be where the infinite loop occurs. anyways, heres the code......can anyone see why this is happening?
Code:#include <iostream> #include <fstream> #include <stddef.h> #include <stdlib.h> #include <ctype.h> #include <string> using namespace std; class search { public: bool check(); //declare the function check void output(); //declare the function output void input(search sight, char *file); void input2(search sight, char *file); 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 ? int a; 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 system[3000][30]; char next;//variable for next character in }; void main() { char *name = "text1.txt"; search sight1; sight1.input(sight1, name); } void search::input(search sight, char *file) { 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)) { in_stream.get(next); cout << next; } } } }



LinkBack URL
About LinkBacks


