Nasir Khan <> spoke thus:
> main()
> {
> struct emp
> {
> float sal;
> };
> struct emp empl;
> scanf("%f",&empl.sal);
> printf("%f",empl.sal);
> }
First, note the differences between your code and
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
struct emp
{
float sal;
};
struct emp empl;
scanf("%f",&empl.sal);
printf("%f\n",empl.sal);
return( EXIT_SUCCESS );
}
1) You included no header files. All bets are immediately off.
2) main() returns int, although C89 will let you get away without
saying so.
3) Omitting the trailing newline may cause problems depending on your
implementation.
> This program compiles fine but at run time I get error. I am using
> Borland C on windows.
What error? Neither bcc32 5.4 nor gcc 2.95.3 complains at compile
time or run time; bcc32 5.4 even compiles your original broken code
and runs it cleanly. You'll have to be more specific about what
you're doing and what's going wrong; and before you do, read the
following links:
http://www.ungerhu.com/jxh/clc.welcome.txt
http://www.eskimo.com/~scs/C-faq/top.html
http://benpfaff.org/writings/clc/off-topic.html
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.