1

Very basic, asking user to input double float amongst other data types. long double is outputed as 0.

i tried checking for logic errors, found none.

long double example;
printf("please enter a very big float\n");
scanf("%Lf",&example);
printf("your big float is %Lf",example);

i expected any float i enter to return a value, long double is 16 byte data thus can accept very large inputs. i got 0;

EDIT: i am using the IDE DEV C++, i think it uses the TDM 4.9.2 64 bit debug gcc but i am very new and have no clue. i am following an old book called c for engineers by B Bramer and S Bramer. it had to have been released prior to 1993. I hope this context helps.

#include<stdio.h>

    char char_1,char_2,char_3;  // 1 byte
    int int_i;                  // 4 bytes
    long int long_int_i;        // 4 bytes
    float float_value;          // 4 bytes
    double double_value;        // 8 bytes
    long double long_double_value;  //16 bytes



int main()
{
    printf("please enter a char, int and long int\n");
    scanf("%c %i %li",&char_1,&int_i,&long_int_i);

    printf("%c %i %li \n",char_1,int_i,long_int_i);

    printf("please enter a float, double and long double \n");
    scanf("%f %lf %Lf",&float_value,&double_value,&long_double_value);

    printf("%f %lf %Lf",float_value,double_value,long_double_value);


}

data entered is a,10,1000 followed by output of a,10,1000 followed by data input of 10, 10.001, 10.00009 followed by ouput of 10, 10.001000, 0

xganh zu
  • 25
  • 6
  • Although my answer's correct it would be *really* nice if an expert answered with standard references... – Bathsheba Aug 22 '19 at 15:14
  • @Bathsheba I'm pretty sure long double is mandatory, but it may have the same precision as double if not supported? – Lundin Aug 22 '19 at 15:19
  • @Lundin: Perhaps it is now, but when I was at University I played with a Solaris box with a 128 bit long double, and we needed to use non-standard IO functions for this reason. I'll recheck. – Bathsheba Aug 22 '19 at 15:21
  • 2
    The problem may be in some part of the code that you didn't show. Please post a [small, **complete** program that reproduces the problem](https://stackoverflow.com/help/minimal-reproducible-example) and tell us exactly what you're entering and what compiler you're using. – Gilles 'SO- stop being evil' Aug 22 '19 at 15:22
  • Are you using the mingw GCC compiler? If so, it doesn't support `long double` properly. – interjay Aug 22 '19 at 15:22
  • Even C89/C90 requires support of `long double` in `scanf` and `printf`. (C99 added `` functions that work on `long double`, e.g. `sinl`, `expl`, etc.). But as pointed out by @interjay, there are various compatibility problems with MinGW. – Ian Abbott Aug 22 '19 at 16:09
  • ok i am new i cannot past my code here so i will edit comment please advise me if this is the incorrect way of doing it. – xganh zu Aug 23 '19 at 19:07

0 Answers0