I tried to read a 3001 x 90 .csv data file into a two dimension array and then divide the array into three 3001 x 30 arrays. Then I tried to build a loop to repeatedly save each 3001 x 30 array into a .txt file, LIN_4.txt, (expecting to overwrite by the old file). My code did not work. Any helps will be appreciated.
This code does not look like it will compile because your braces are mismatched. Could you check that and your indentation, then describe what you mean by "does not work"? How does it not work? Do you get an error message? Strange output?
Without seeing the input file, verifying what is wrong is extremely difficult. I suspect that you're probably not reading the input file correctly.
Also with the sizes of your arrays I would recommend you consider using vectors instead.
Opening and closing your output file inside the loop is probably not the best thing to do. Why not open the file prior to the loop?
Lastly this: LIN_4 << dat[3001][30];
Is accessing your array out of bounds. By the way this is not how you print an array, this is trying to print a single element.
Thanks, jlb. The input file contain 3001 rows and 90 columns with the first row containing the variable names: x1, x2....x30....x1,x2,....,x30....x1,x2,....x30. All are data are binary: 0s and 1s.
I see what you meant with dat[3001][30]. I will fix it and try again. Also, will try to fix the structure of the loop based on you suggestion.