//Prototypes
//int data_file_open(ifstream & file_buffer); // initialize function to open files
int data_file_open (ifstream & file_buffer)
{
string programmer;
string storedfile; // blank string declared
cout << "hello! what is your name?!" <<endl;
getline (cin,programmer);
cout << "Which file does " << programmer << " wish to open?!\n"; //prompt user to open file
getline (cin,storedfile); // takes user's input and stores into storedfile
file_buffer.open (storedfile); // opens file if file exist
if (file_buffer.fail())
{
cout<< "Filename not found " << programmer << ". Check your spelling\n";
return 0;
}
cout << programmer << ", your file has been opened " << endl;
//file_buffer.close();
return 1;
}
///// fills an array ////////
int fill_array_from_file (unsigned int ARRAY_SIZE, ifstream &file_buffer, double array1[])
Maybe you need something more like this:
(changed array1 to char array, because chars are what you get from file.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int fill_array_from_file (unsignedint ARRAY_SIZE, ifstream &file_buffer, char array1[])
{
int counter= 0;
while (!file_buffer.eof() && counter<ARRAY_SIZE)
{
array1[counter++] = file_buffer.get(); // get next letter from file and ++ counter
cout << array1[counter-1]; // cout one letter at a time
// could also be done after the loop
// cout << file_buffer << endl; // not cout file_buffer address 100 times
}
cout << endl;
cout << array1 << endl; // cout entire array once
return counter;
}
int position_next (int start_pos, string nullstring)
{
if (start_pos >= nullstring.length())
return -1;
////// array[i] == ' ' ////////////
while (nullstring[start_pos] == ' ') //check the variable in textstring whether is blank
{
start_pos++;
if (start_pos>= nullstring.length()) //start position cant' be larger than array or text length
return -1;
}
return start_pos; // returns the array element /// position of the start
}
// word_length function
int word_length(int start_pos, string nullstring)
{
while (nullstring[start_pos] != ' ') //check the variable in textstring whether is still a chararcter
{
start_pos++; //increment until start_pos reaches a char
cout << start_pos<<endl;
if (start_pos>= nullstring.length()) //start position cant' be larger than array or text length
return -1;
}
return start_pos; // returns the array element /// position of the start
}
///parse140///
/*string pp_breaker(string my_string[], int ARRAY_SIZE, string nullstring, int listlength) // breaks paragraph into words function
{
start_pos= 0, my_string[]
}*/
int _tmain(int argc, _TCHAR* argv[])
{
int o =0;
string TEST("What time "); //begin of testimg program functions
cout<<"enter words"<<endl;
getline (cin ,TEST);
position_next (o, TEST);
o = position_next (o, TEST);
cout<<o<<endl;
word_length(o, TEST);
o = word_length(o, TEST);
cout<<o<<endl;
cout<< TEST<< endl;
system ("pause");