assigning values to an array 
Author Message
 assigning values to an array

I'm trying to read a part of a file into an array so i can use it
as a reference table later.

This is what I've done:

                for (i = 0;i < PART; i++)
                        {
                        for (j = 0; j < NAME; j++)
                                {
                                fscanf (tables_ptr, "%f", &price);
                                prices_ary [i] [j] = price;
                                }
                        }  /*  end for  */

The assignment to price works fine, but the assignment to
prices_ary [i] [j] just sits at 0.0 the whole time. Both price
and prices_ary have been declared as float.

Additionally, I had tried:
                fscanf (tables_ptr, "%f", prices_ary [i] [j]);

Why didn't that work?  Might this all be compiler related (using
Borland)?

Thanx,

Daniel M. Kernan
-----------------
"With a wound, spirits soar and virtue thrives."
--Furius of Antium
--



Sun, 17 Mar 2002 03:00:00 GMT  
 assigning values to an array


Quote:
>The assignment to price works fine, but the assignment to
>prices_ary [i] [j] just sits at 0.0 the whole time. Both price
>and prices_ary have been declared as float.

>Additionally, I had tried:
>                fscanf (tables_ptr, "%f", prices_ary [i] [j]);

>Why didn't that work?  Might this all be compiler related (using
>Borland)?

Post your declarations of price and prices_ary.

Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
--



Mon, 18 Mar 2002 03:00:00 GMT  
 assigning values to an array

Quote:

> I'm trying to read a part of a file into an array so i can use it
> as a reference table later.

> This is what I've done:

>                 for (i = 0;i < PART; i++)
>                         {
>                         for (j = 0; j < NAME; j++)
>                                 {
>                                 fscanf (tables_ptr, "%f", &price);
>                                 prices_ary [i] [j] = price;
>                                 }
>                         }  /*  end for  */

> The assignment to price works fine, but the assignment to
> prices_ary [i] [j] just sits at 0.0 the whole time. Both price
> and prices_ary have been declared as float.

What do you mean?
How do you know that the assignment didn't work?
Perhaps your code that reads prices_ary was wrong, because
this code should work.

Quote:

> Additionally, I had tried:
>                 fscanf (tables_ptr, "%f", prices_ary [i] [j]);

> Why didn't that work?  Might this all be compiler related (using
> Borland)?

You're missing a reference.  Try &prices_ary[i][j].

/peter
--



Mon, 18 Mar 2002 03:00:00 GMT  
 assigning values to an array

Quote:

>                                 fscanf (tables_ptr, "%f", &price);
> Why didn't that work?

My guess (since you didn't show enough of the code) is that
you declared price as other than float, or that the input
via tables_ptr was not of the expected form.
--



Mon, 18 Mar 2002 03:00:00 GMT  
 assigning values to an array
sorry about not responding to your replies to message.  We
weren't getting feed until this afternoon.  I've managed to find
the problem.  Of course, I feel rather foolish now.  The reason I
thought price_ary [i][j] sat at zero, is because the watch I had
on it stayed at zero as I stepped through the code.  What I
didn't think of is that i incremented immiediately after the same
code thus making it look like 0.0 the whole time.  There was also
a problem with the format of the input file.  I had previously
thought that fscanf stopped at and discarded the newline
character.  

Sorry if you think I wasted your time.  Your effort is
appreciated.  I'll try to include more info. when I post too.

Daniel M. Kernan

Quote:

> I'm trying to read a part of a file into an array so i can use it
> as a reference table later.

> This is what I've done:

>                 for (i = 0;i < PART; i++)
>                         {
>                         for (j = 0; j < NAME; j++)
>                                 {
>                                 fscanf (tables_ptr, "%f", &price);
>                                 prices_ary [i] [j] = price;
>                                 }
>                         }  /*  end for  */

> The assignment to price works fine, but the assignment to
> prices_ary [i] [j] just sits at 0.0 the whole time. Both price
> and prices_ary have been declared as float.

> Additionally, I had tried:
>                 fscanf (tables_ptr, "%f", prices_ary [i] [j]);

> Why didn't that work?  Might this all be compiler related (using
> Borland)?

> Thanx,

> Daniel M. Kernan
> -----------------
> "With a wound, spirits soar and virtue thrives."
> --Furius of Antium
> --


--



Wed, 20 Mar 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. assigning values to an array of type void?

2. assigning an array to values.

3. Scheduled c# application and how to assign customizable value through scheduled task

4. How to assign a value to unsigned long variable

5. I cannot assign value to the variable

6. Problems assigning const fields in a class to an initial value

7. assigning the value of a char to a string (newbie)

8. Assigning values to structure variables

9. assigning 'misaligned value' to a pointer

10. Assigning out-of-range value to signed int

11. assign binary value to a variable

12. Repost: How to assign consecutive values to struct

 

 
Powered by phpBB® Forum Software