1234
12 13 22 22 43 45 23 54 87 89 98 88 34 55 76 88 8 88 45 32 45 28 98 88
{45, 32, 45, 28, 98, 88}, {34, 55, 76, 88, 8, 88}, {23, 54, 87, 89, 98, 88}, {12, 13, 22, 22, 43, 45},
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
#include <iostream> #include <fstream> #include <cstring> #include <stdlib.h> using namespace std; const int row = 4, column = 6; void splitData(int [][column], const string& = " "); void outputArray(const int [][column]); int main() { int numberArrays[row][column] = {}; string line; ifstream iFile("numbers.txt"); //assuming 'numbers.txt' is in this source code's directory if(iFile) { while(getline(iFile, line)) splitData(numberArrays, line); outputArray(numberArrays); } else cout << "The file could not be found!\n"; return 0; } void splitData(int numberArrays[][column], const string& line) { static int lineLength = line.length(), columnCounter = 0, rowCounter = row - 1; char newLine[lineLength + 1]; char *p; for(int i = 0; i < lineLength; i++) newLine[i] = line[i]; newLine[lineLength] = '\0'; p = strtok(newLine, " "); while(p) { numberArrays[rowCounter][columnCounter++] = atoi(p); p = strtok(NULL, " "); } columnCounter = 0; rowCounter--; } void outputArray(const int numberArrays[][column]) { ofstream oFile("numbers_updated.txt"); for(int i = 0; i < row; i++) { for(int j = 0; j < column; j++) oFile << numberArrays[i][j] << ' '; oFile << endl; } }