Newbie Array/Scanf Problem 
Author Message
 Newbie Array/Scanf Problem

I am trying to write a program that has the user fill a dual array with floating point
numbers. I can not seem to be able to get scanf to work if I use variables to
represent the elements of the array. The two code fragments below were cut and pasted
from an actual program. The first example where I use constants to represent the array
elements in the scanf statment works just fine. The second however, where I use
variables to substitute for the array elements, does not work. I get the error message
that follows (By the way, I am using Turbo C++, v1.01, aka Second Edition. The only
library I have included is stdio.h):

float arr[5][2];
int i,j;

scanf("%f", &arr[0][0]);
printf("You entered %f", arr[i][j]);

OUTPUT Screen:

3
You entered 3.000000

***********************************

***********************************

float arr[5][2];
int i,j;

i=0;
j=0;

scanf("%f", &arr[i][j]);
printf("You entered %f", arr[i][j]);

OUTPUT Screen:

 scanf : floating point formats not linked
 Abnormal program termination

------------------------------------------

What am I doing wrong!!

Please reply via e-mail. Thanks!




Wed, 05 May 1999 03:00:00 GMT  
 Newbie Array/Scanf Problem

I am trying to write a program that has the user fill a dual
array with floating point numbers. I can not seem to be able to
get scanf to work if I use variables to represent the elements of
the array. The two code fragments below were cut and pasted from
an actual program. The first example where I use constants to
represent the array elements in the scanf statment works just
fine. The second however, where I use variables to substitute for
the array elements, does not work. I get the error message that
follows (By the way, I am using Turbo C++, v1.01, aka Second
Edition. The only library I have included is stdio.h):

float arr[5][2];
int i,j;

scanf("%f", &arr[0][0]);
printf("You entered %f", arr[i][j]);

OUTPUT Screen:

3
You entered 3.000000

***********************************

***********************************

float arr[5][2];
int i,j;

i=0;
j=0;

scanf("%f", &arr[i][j]);
printf("You entered %f", arr[i][j]);

OUTPUT Screen:

 scanf : floating point formats not linked
 Abnormal program termination

------------------------------------------

What am I doing wrong!!

Please reply via e-mail. Thanks!




Wed, 05 May 1999 03:00:00 GMT  
 Newbie Array/Scanf Problem

: I am trying to write a program that has the user fill a dual
: array with floating point numbers. I can not seem to be able to
: get scanf to work if I use variables to represent the elements of
: the array. The two code fragments below were cut and pasted from
: an actual program. The first example where I use constants to
: represent the array elements in the scanf statment works just
: fine. The second however, where I use variables to substitute for
: the array elements, does not work. I get the error message that
: follows (By the way, I am using Turbo C++, v1.01, aka Second
: Edition. The only library I have included is stdio.h):

* I named it 'first list'.
:: float arr[5][2];
:: int i,j;

:: scanf("%f", &arr[0][0]);
:: printf("You entered %f", arr[i][j]);

:: OUTPUT Screen:

:: 3
:: You entered 3.000000
Does it work correctly ?! It's incredible..!!!
Two integer variables, i and j, is declared, but not initialized.
The variable must be initialized before
it used. It is very dangerous if you does not initialize the variable.
When you declared a variable, compiler allocates some memory area for
the variable. But nobody knows what values stored in the allocated area.
So, YOU MUST BE INITIALIZED VARIABLES BEFORE YOU USE THEM. Okay?

: ***********************************
* I named it 'second list'.
: ***********************************

: float arr[5][2];
: int i,j;

: i=0;
: j=0;
above two lines,'i=0; / j=0;' means initialization.
Initialization is not difficult.
Initialization is that give a value to a variable before they be used.

: scanf("%f", &arr[i][j]);
: printf("You entered %f", arr[i][j]);

: OUTPUT Screen:

:  scanf : floating point formats not linked
:  Abnormal program termination

: ------------------------------------------
I think that the 'second list' works correctly
but the 'first list' works incorrectly.

: What am I doing wrong!!

: Please reply via e-mail. Thanks!


Thank you.



Thu, 06 May 1999 03:00:00 GMT  
 Newbie Array/Scanf Problem

: I am trying to write a program that has the user fill a dual array with floating point
: numbers. I can not seem to be able to get scanf to work if I use variables to
: represent the elements of the array. The two code fragments below were cut and pasted
: from an actual program. The first example where I use constants to represent the array
: elements in the scanf statment works just fine. The second however, where I use
: variables to substitute for the array elements, does not work. I get the error message
: that follows (By the way, I am using Turbo C++, v1.01, aka Second Edition. The only
: library I have included is stdio.h):

: float arr[5][2];
: int i,j;

: scanf("%f", &arr[0][0]);
: printf("You entered %f", arr[i][j]);

: OUTPUT Screen:

: 3
: You entered 3.000000

: ***********************************

: ***********************************

: float arr[5][2];
: int i,j;

: i=0;
: j=0;

: scanf("%f", &arr[i][j]);
: printf("You entered %f", arr[i][j]);

: OUTPUT Screen:

:  scanf : floating point formats not linked
:  Abnormal program termination

: ------------------------------------------

: What am I doing wrong!!

Nothing really. Although using scanf is debatable, in this case it's
your compiler. It's simply crap. Definitely not conformant to the ANSI
standard. It's not linking in the floating point library modules. That
qualifies it as pure garbage. Since it's from Borland, I am not
surprised.

--

If it doesn't work, you're doing it wrong,
If it does, you just got lucky.



Thu, 06 May 1999 03:00:00 GMT  
 Newbie Array/Scanf Problem

Quote:

> : float arr[5][2];
> : int i,j;

> : i=0;
> : j=0;
> above two lines,'i=0; / j=0;' means initialization.
> Initialization is not difficult.
> Initialization is that give a value to a variable before they be used.

> : scanf("%f", &arr[i][j]);
> : printf("You entered %f", arr[i][j]);

> : OUTPUT Screen:

> :  scanf : floating point formats not linked
> :  Abnormal program termination

> : ------------------------------------------
> I think that the 'second list' works correctly
> but the 'first list' works incorrectly.

> : What am I doing wrong!!

> : Please reply via e-mail. Thanks!


> Thank you.

Did you include stdio.h ?
You need a line of code like this
#include <stdio.h>
--
F. P. Marin

URL: http://tierra.ciens.ucv.ve/~fmarin/lfts.html

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                
ADDRESS                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                        
%
%                               F. P.
Marin                               %
%                    Universidad Central de
Venezuela                     %
%                          Facultad de
Ciencias                           %
%                     Escuela de Fisica y
Matematica                      %
%                         Departamento de
Fisica                          %
%                Laboratorio de Fisica Teorica de
Solidos                 %
%                 A.P. 47586. Caracas 1041-A.
VENEZUELA.                  %
%                                                                        
%
%%%%%%%%%%%%%%



Sat, 15 May 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Newbie Array/Scanf question

2. Newbie problem w/ scanf

3. newbie problem with scanf

4. scanf problem (DATA/MEMORY CONCEPT) (newbie)

5. Newbie - while loop & scanf problems

6. Newbie Array Problem - how to strncpy from an array of char

7. Read file to array problem (Newbie for those wishing to avoid)

8. newbie char array assignment problem

9. Newbie problem with arrays

10. Newbie Function/2D array problem

11. Newbie Array Problem - how to strncpy fr

12. Newbie Array Problem BC/C++ v4.0

 

 
Powered by phpBB® Forum Software