Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scanf() used for common variable do

Status
Not open for further replies.

hughLg

Programmer
Feb 18, 2002
136
0
0
MY
scanf() used for common variable does works. when variable like double and long double within the structure get from scanf(), undesireable result produces.
 
sure.

#include <stdio.h>

typedef struct stock {
char id[5];
float num;
double num1;
long double num2;
} stock_t;

int
main()
{
stock_t var;
scanf(&quot;%f&quot;, &var.num);
/* following 2 cause unexpected result. */
scanf(&quot;%f&quot;, &var.num1);
scanf(&quot;%f&quot;, &var.num2);
return 0;
}
 
Its not because of scanf, but becuase you have used %f for double & long double.
 
Try:
Code:
   scanf(&quot;%lf&quot;, &var.num1);
   scanf(&quot;%llf&quot;, &var.num2);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top