5. You need to get a book on C...
Kinda harsh reply dont you think?
----
"You know the one thing that's wrong with this country? Everyone gets
a chance to have their fair say." - Bill Clinton, May 29, 1993
On Thu, 18 Feb 1999, Glynn Clements wrote:
>
> [PS: your clock is off by a month]
>
> Chris wrote:
>
> > what am i doing wrong here. it compiles and works but after you enter in
> > the first value it just stops. /*
>
> > if ( ( j = read_x1( x1 ) ) == 'E' );
> > return EXIT_FAILURE;
>
> [snip]
>
> > float read_x1( float x1 )
> >
> > {
> >
> > printf( "\nenter x1: " );
> >
> > if ( scanf( "%f" , &x1 ) != 1 )
> > {
> > printf( "\nFailed to read entered value\n" );
> > x1 = 'E';
> > return x1;
> > }
> >
> > return x1;
> >
> > }
>
> 1. This (and the x2/y1/y2 versions) won't work. C uses call-by-value,
> not call-by-reference. You would use either
>
> float read_x1( void )
> or
> void read_x1(float *px1)
>
> instead.
>
> 2. there isn't any point having four (nearly) identical functions,
> which differ only in the prompt. Use something like:
>
> float read_float(const char *prompt)
> {
> float x;
>
> printf( "enter %s: ", prompt );
> fflush( stdout );
>
> if ( scanf( "%f" , &x ) != 1 )
> {
> fprintf( stderr, "Failed to read entered number\n" );
> return NAN; /* IEEE Not-A-Number */
> }
>
> return x;
> }
>
> 3. However, the reason why your program is failing is that you are
> unconditionally returning after the call to read_x1(). The indentation
> doesn't match the presence of the semicolons; you wrote:
>
> if ( ( j = read_x1( x1 ) ) == 'E' );
> return EXIT_FAILURE;
>
> but it would be more accurate to write
>
> if ( ( j = read_x1( x1 ) ) == 'E' )
> ;
> return EXIT_FAILURE;
>
> I.e. you are conditionally executing an empty statement, then
> unconditionally returning. Remove the semicolon, i.e.
>
> if ( ( j = read_x1( x1 ) ) == 'E' ) /* no semicolon here */
> return EXIT_FAILURE;
>
> 4. This has nothing to do with Linux. The above is all vanilla ANSI C,
> and would apply equally to MS-DOS or VMS.
>
> 5. I think that you need to get a book on C.
>
> --
> Glynn Clements <[EMAIL PROTECTED]>
>
>