So I ave my readtext1 file which has a bunch of words in sentences.
Then I make it so it's a word per sentence using split_by_sentence.
Then I feed in a word or line at a time into into the excel_file function.
Then I split the word into chars by for looping through the word, and passing each char to the excel file cell.
It works fine but I am only getting the last word, and not the full word but parts of the word.
I want the entire word in the excel file, not a partial word, and I want every word not just the last word
Here is my code;
I'm using codeblocks not visual studio, so there is no functional spaces or tabs format option. So I'm sorry if my code is hard to read.Code:#include <iostream> #include <string> #include <string.h> #include <fstream> #include <vector> #define MAX_STRING 4096 using namespace std; void delete_char(char *src, char n, int len) { char *dst; int i; // Do not remove NULL characters. if ( n == 0 ) return; // Small attempt to control a buffer overflow if the // the string is not null-terminated and a proper length // is not specified. if ( len <= 0 ) len = MAX_STRING; dst = src; for ( i = 0; i < len && *src != 0; i++, src++ ) { if ( *src != n ) *dst++ = *src; } // Ensure the string is null-terminated. *dst = 0; return; } void excel_file (std::string str) { ofstream MyExcelFile("example.csv"); if(!MyExcelFile.is_open()){ cout << "The MyExcelFile file is not open" << endl; } char * writable = new char[str.size() + 1]; std::copy(str.begin(), str.end(), writable); writable[str.size()] = '\0'; char dels[] = ".\n`1234567890-=~!@#$%^&*()_+[]\\{}|;\':\",/<>?$"; int i = 0; for ( i = 0 ; dels[i] != '\0' ; i++ ) { delete_char(writable, dels[i], 0); } for ( i = 0 ; writable[i] != '\0' ; i++ ) { MyExcelFile << writable[i] << ","; i++; } MyExcelFile.close(); } void split_by_sentence(void){ int character, file_character=0; char buffer[1024]; ifstream book ("readtext1.txt"); if(!book.is_open()){ cout << "The book file is not open" << endl; } ofstream book2 ("readtext.txt"); if(!book2.is_open()){ cout << "The book2 file is not open" << endl; } while(file_character!=EOF){ buffer[0]='\0'; for(character=0;character<sizeof(buffer);character++) { file_character=book.get(); if(file_character==EOF) break; if(file_character=='.') { buffer[character]='\0'; break; } if(file_character=='?') { buffer[character]='\0'; break; } if(file_character=='!') { buffer[character]='\0'; break; } if(file_character==' ') { buffer[character]='\0'; break; } if(file_character==',') { buffer[character]='\0'; break; } buffer[character]=file_character; } if(file_character==EOF) break; book2 << buffer << "." << endl; } book.close(); book2.close(); } int main() { int j = 0; vector<string> text_file; split_by_sentence(); ifstream ifs ("readtext.txt"); string temp; if(!ifs.is_open()){ cout << "The ifs file is not open" << endl; } while( getline( ifs, temp ) ){ for (j = 0; temp[j] != '\0'; j++) temp[j] = tolower(temp[j]); excel_file(temp); text_file.push_back( temp ); } ifs.close(); }



LinkBack URL
About LinkBacks


