plz remove error in my c program

Status
Not open for further replies.

arunks

Hey here is the aks
i wrote a program which is given below

Code:
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[5];
char deptt[5];
int idcode;
float s;
};

void main()
{
struct employee emp[2];
int i,j;
clrscr();
for(i=0;i<2;i++)
{
gets(emp[i].name);
gets(emp[i].deptt);
scanf("%d",&emp[i].idcode);
scanf("%f",&emp[i].s);
}
getch();
}


but when i run it after asking three values name then deptt then idcode then it gives the following error

Code:
scanf: floating point formats not linked
abnormal program termination

plz see why this is so.. and make my program error free

if u want then run it in C and see urself when error comes

PROGRAM2 : another program i have writeen is also not showing ouput as expected..

Code:
#include <stdio.h>
#include <conio.h>

struct test ** display(struct test*);  //function prototype
//structure delaration starts here
struct test
{
int cnt;
int chr;
};

void main(void)
{
struct test tst,**tt;
clrscr();
tt=display(&tst);

printf("cnt: %d \n ", (*tt)->cnt);
printf("chr: %c \n ", (*tt)->chr);

getch();


}

struct test ** display(struct test *ptr)
{
ptr->cnt = 1;
ptr->chr = 'a';
return(&ptr);
}



it doesnt print value of chr.
why is it so and plz correct it
 
Last edited:

Digit_Dragon

Old Stock in New Bottle!!
Hi Dude,
For the first program there is no error......you enter name and deptt .....only problem is in the output the values are not getting assigned properly. Because of your gets and scanf.

Whenever you program make it user friendly give some statements like Enter the name, Enter the Dept, then scanf it to required variable.

Anyway when compiled and run the program has no error.
 
OP
arunks

arunks

Hey here is the aks
ya program has error when u enter first three values ..first u enter a name then enter a deptt then enter a integer idcode then error will come regarding floating linking something and no problem is coming with using gets and scanf...


as if i chage idcode variable to int type instead of float then it works fine..
the program gives error when it is of float type..

Anybody plz help.......
 
Status
Not open for further replies.
Top Bottom