getData for multidimensional array! *IMPORTANT

I have to read this input file of arrays. The first column is divers second column is difficulty and third array is 5 judges scores.

HOW do input this file and put them in the arrays:

char divers [MAX_DIVERS][LEN]; //char array for names
double difficulty [MAX_DIVERS]; //array for difficulty
double scores [MAX_DIVERS][JUDGES]; // 2dim array for scores

KNIFE JACK 1.3 6.0 5.1 6.3 5.9 6.5
WILLIAMSON FLIP A 1.4 3.5 4.1 4.7 7.2 3.8
SOMMER TODD 1.2 8.0 9.1 8.1 9.3 9.0
SWAN MIKE 1.1 4.3 2.1 9.9 6.2 7.0


#define MAX_DIVERS 50
#define LEN 20
#define JUDGES 5
/* :::::::::::::::::::::::getData:::::::::::::::::::::::::::
void getData(FILE* fpIn, char divers[][LEN], double difficulty[], double scores[][JUDGES])
{
int i;
int j;

while (fgetc(fpIn) !='\n');

for(i = 0; i < MAX_DIVERS; i++){

fscanf(fpIn, "%c", &divers[i]);

}

return;
}
closed account (4Gb4jE8b)
I'm presuming the data is in a .txt file or some similar file, at which point you'd want to use fstreams. I'm a little confused about how they are separated into columns, but you could relatively easily read the whole file into memory and parse the text as necessary (especially if there is a certain character such as a tab separating them into columns).

If i am misunderstanding, please explain a little more clearly.
I can't use streams.

What I mean by colums is that the txt file needs to be broken up in 3 different arrays broken up by white spaces
I have to use for loops I just don't know how to use them with 2 dimensonal arrays and multilpe fscanfs

char divers [MAX_DIVERS][LEN]; //char array for names
double difficulty [MAX_DIVERS]; //array for difficulty
double scores [MAX_DIVERS][JUDGES]; // 2dim array for scores
closed account (4Gb4jE8b)
You can't use streams eh? Other than the obvious "why?" I'm then at a loss. I don't know of anyway to even open a file without using a stream. Hmm... honestly I don't know how i'd do any of what you're saying with those methods.

If it means anything, I'd use fstreams to open the file, run a while loop to get the whole file into memory, and parse the data either through stringstreams or a series of string.find/rfind statements, convert the necessary strings into ints, and feed them into the array with a for loop in a similar fashion you showed above.

Sorry I couldn't help more... Hoping someone more qualified comes to help!
Last edited on
It is because I am in an intermediate C class I don't even know what a stream is. We are learning 2 dim arrays and fscanf to put different parts of file into different arrays with different dimensions.

I just don't know how to write it with the nested forloops or while statements.

Thanks for your response it is much appreciated!
closed account (4Gb4jE8b)
well for some reading on the subject
in out stream
http://www.cplusplus.com/reference/iostream/iostream/
file streams
http://www.cplusplus.com/reference/iostream/fstream/
string streams
http://www.cplusplus.com/reference/iostream/stringstream/

they're pretty useful for console apps, though I'd be willing to bet any API or GUI would replace their use.
Topic archived. No new replies allowed.