I've a file like this
C 1.009 0.987 8.987 89.098
H 2.898 3.087 6.876 5.87
H 3.456 2.345 2.67 8.876
S 2.734 3.45 3.123 5.67
I want to write each column into an array, I got a code from the article 'Inputing from file to parallel arrays'tried to modify it but cannot use, cannot read the output. I have it in a function so I can re-use it. The length of the column is mostly known, but varies from different files. Please can somebody help me.
My code is below:
i dont think you can return those many elements ... i thought a function always returns one value ... and that is supposed to match with the return type mentioned before the function name (ex. double in line 8).
you might want to pass pointers as your arguments so you wont have to return anything
Honestly if you can't use pointers yet I think this problem is a bit beyond you KingJosh. I suggest reading the tutorial on this site. Also why don't you post what you have so far.
You are right acpaluri, functions can return either zero values (void), or one value.
Thanks for the great lessons. It's not a home work. I want to do this so, I can use it to write some code to help me with my research. I use matlab but think I should change my codes to c++ so i can share them for free. I will like to do it myself so i can learn in the process. This part seems to be the most difficult, have been battling with it for weeks but felt I should share the problem. Thanks to all who have and are still contributing to it. Special thanks to Acapaluri.
1 2 3
The code compiled but does not display output when I run.
Also, the num_elements I will like to read from the file.
please note that in the code that you posted you are declaring 4 arrays while there are five columns in the data file ... and the use of eof in a while loop (from what i know) is not a good practice ... i have modified the code above ... also you need to take care that there are no extra lines or white spaces at the end in your input files.