Read file, write to array, find min and max
-
If not using STL at all is an option, you might ask yourself why you store the numbers in an array in the first place. Just keep track of the smallest and largest numbers you fscanf'ed so far.
it sounds like he has to for a homework assignment. It sounds like a pretty lame homework assignment, must have been a math teacher turned programming teacher. -- Rocky Dean Pulley
-
As you are reading in the numbers, if
num_elements
is a multiple of 100, then callbiggest()
andsmallest()
. Another way would be to read all of the numbers in the file, and call thebiggest()
andsmallest()
functions once for each group of 100 numbers, like:big1 = biggest(table, 100); // search the first 100 numbers
big2 = biggest(&table[100], 100); // search the second 100 numbers
big3 = biggest(&table[200], 100); // search the third 100 numbersMake sense?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
it sounds like he has to for a homework assignment. It sounds like a pretty lame homework assignment, must have been a math teacher turned programming teacher. -- Rocky Dean Pulley
-
I can't really do your homework for you, you won't learn anything that way. Besides, you are 90% there, just take the time and figure it out, you're almost done. -- Rocky Dean Pulley
-
I can't really do your homework for you, you won't learn anything that way. Besides, you are 90% there, just take the time and figure it out, you're almost done. -- Rocky Dean Pulley
-
Yes, but how can i write big10489=biggest(&table[1048800], 100); ? This will take a lot of my time. And i don?t now, if file is so long?
dr.eu wrote: Yes, but how can i write big10489=biggest(&table[1048800], 100); ? Exactly like that. This assumes that you have read at least 1,048,900 numbers from the file.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
Yes, from that almost i am gona crazy. The result is O.K. (for all numbers in file). Help me please with 100, 200, ... elements in array !!!
just use the same array, once you hit a number where (current_number % 100 == 0) then do your biggest/smallest check and reset current_number to 0, keep going on after that and it will just reuse your 100 item array. -- Rocky Dean Pulley
-
dr.eu wrote: Yes, but how can i write big10489=biggest(&table[1048800], 100); ? Exactly like that. This assumes that you have read at least 1,048,900 numbers from the file.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
just use the same array, once you hit a number where (current_number % 100 == 0) then do your biggest/smallest check and reset current_number to 0, keep going on after that and it will just reuse your 100 item array. -- Rocky Dean Pulley
-
I done so: while (fscanf(in,"%f",&element) != EOF) { table[num_elements] = element; current_number=element; current_number%100==0; num_elements++; } but steel dont work propertly.
How about:
while (...)
{
table[num_elements] = element;
num_elements++;
if ((num_elements % 100) == 0)
{
biggest(...);
smallest(...);
num_elements = 0;
}
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
How about:
while (...)
{
table[num_elements] = element;
num_elements++;
if ((num_elements % 100) == 0)
{
biggest(...);
smallest(...);
num_elements = 0;
}
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
I try, but compiler return erors: too few arguments to function `float * biggest(float *, int)' at this point in file too few arguments to function `float * smallest(float *, int)' at this point in file
I don't mean to sound mean but you should really be able to figure that one out. -- Rocky Dean Pulley
-
I don't mean to sound mean but you should really be able to figure that one out. -- Rocky Dean Pulley