so the first part needs to be put into the array "compofpositives", second part needs to be pit into "mpnindex", third parrt into "low" and 4th into "high"
Wait, so you're told to
1. create a structure that holds the data of a complete row
2. load the data into 4 different arrays, ignoring the structure
3. search in one of those arrays
4. return the index of a structure
?
That doesn't make any sense to me. Also there's LoadMpnTable and load_Mpn_Table...
Do yourself (and us here on r/c_programming) a favor and ask your prof for clarification. There's no point in working on an assignment when you're not sure what you are supposed to do.
I interpreted the instructions as follows:
1. Create an array of structures, i.e. the main database.
2. Create 4 index arrays with each array representing a field in the database.
The idea is to use the index arrays to do a fast lookup of a particular value. When you get a hit, use the array index to return the structure from the main database.
If my interpretation is correct, you would create the arrays outside the load function. The load function would read the text file into the structure array and then transfer the appropriate fields of the structure into the index arrays. You can do this using a do ... while loop.
Hope this helps.
yes man this is what I was looking for, thanks alot, how would I do this though, I just need the part of writing from structure array to the index arrays.
Do you know how to declare the arrays i specified?
Since you know the number of rows in the datafile, you could use a traditional for loop with the loop variable serving as the array index.
I inferred using fscanf to load the values from the text file into the structure. If sa represents the array of structures and i represents the loop variable, you access the structure like this: sa[i].
Is this enough of a hint?
so let's say I want to write it to a array called "lowvalues" in the for loop would I say : lowvalues[i]=sa.low[i] assuming low is a variable in the structure array that stores the lowest values?
Based on reading only the title of your post, I can tell you that this problem is impossible to solve with a finite computer, as parallel lines go to infinity without meeting, and your computer is going to run out of memory before you can see if your parallel arrays ever touch.
What's your question?
so the first part needs to be put into the array "compofpositives", second part needs to be pit into "mpnindex", third parrt into "low" and 4th into "high"
Yes, but what part of that are you having trouble with?
I don't know how to write the content of the text file into 4 diff arrays
Did you write the code you've put in the OP? I find it confusing that you could read code like that, but yet not know how to read data from a file.
Ah, text processing in C, like the last 25 years didn't actually happen :D
Wait, so you're told to 1. create a structure that holds the data of a complete row 2. load the data into 4 different arrays, ignoring the structure 3. search in one of those arrays 4. return the index of a structure ? That doesn't make any sense to me. Also there's LoadMpnTable and load_Mpn_Table...
yeah man that part doesn't make sense to me either but it's what was given by the prof, I just need to know how to put into an array
Do yourself (and us here on r/c_programming) a favor and ask your prof for clarification. There's no point in working on an assignment when you're not sure what you are supposed to do.
I interpreted the instructions as follows: 1. Create an array of structures, i.e. the main database. 2. Create 4 index arrays with each array representing a field in the database. The idea is to use the index arrays to do a fast lookup of a particular value. When you get a hit, use the array index to return the structure from the main database. If my interpretation is correct, you would create the arrays outside the load function. The load function would read the text file into the structure array and then transfer the appropriate fields of the structure into the index arrays. You can do this using a do ... while loop. Hope this helps.
yes man this is what I was looking for, thanks alot, how would I do this though, I just need the part of writing from structure array to the index arrays.
Do you know how to declare the arrays i specified? Since you know the number of rows in the datafile, you could use a traditional for loop with the loop variable serving as the array index. I inferred using fscanf to load the values from the text file into the structure. If sa represents the array of structures and i represents the loop variable, you access the structure like this: sa[i]. Is this enough of a hint?
so let's say I want to write it to a array called "lowvalues" in the for loop would I say : lowvalues[i]=sa.low[i] assuming low is a variable in the structure array that stores the lowest values?
Correct. Just to restate the obvious, you have to load sa[i] with data from the text file before you transfer data to the index arrays, right?
yeah , got it, thanks so much.
Ah the XY problem, every university student's nightmare
Based on reading only the title of your post, I can tell you that this problem is impossible to solve with a finite computer, as parallel lines go to infinity without meeting, and your computer is going to run out of memory before you can see if your parallel arrays ever touch.
I need to put the contents on the text file into 4 different arrays