#include #include #include using namespace std; int chSpace = 1; int newCell = 1; int newColumn = 1; int fcurserPos = 1; char cellBuffer[512]; char ch; char sp = ' '; char newLine = '\n'; bool newRow = 0; int main(int argc, char **argv) { ifstream fin(argv[1]); cout << "\""; while (fin.get(ch)) { if (ch != sp) { // is this a space? if (chSpace > 3) { // If we need to start a new cell? newCell = 1; // start a new field } if (newCell == 1) { // If this is a new cell: cout << cellBuffer; // output old cell cout << "\","; // start new cell newCell = 0; // Start fresh } if (newRow == 1) { // If this is a new row cout << "\n\""; // output \n" fcurserPos = 1; cellBuffer[fcurserPos] = ch; // copy char to cell buffer newRow = 0; // Start fresh } cellBuffer[fcurserPos] = ch; } if (ch == sp) { chSpace++; } } // while (fin.get(ch)) **END** fin.close(); return 0; }