In structure hen i read floating point value from user and i get the error like"floating point not conneted..."

i have been sugested to write two lines for that
extern void float conetor();
#pragma extref floatconnector

even though i got the same error it is not even asking for float value input.
so is it like system dependent or what?

#include <stdio.h>
#include <conio.h>
typedef struct cricket
{
	char name[20];
	float avg;
}cri;
void main()
{
	 cri c[3];
	 int i;
	 for(i=0;i<3;i++)
	 {
		printf("\n Entr name : ");
		gets(c[i].name);
		printf("\n Enter his batting average: ");
		scanf("%f",c[i].avg);
	 }
	 printf("\n\n Name\tBAverage\n\n");
	 for(i=0;i<3;i++)
	 {
		printf("\n%s\t%f",c[i].name,c[i].avg);
	 }
	 getch();
}

//ERROR : floating point format not connected .Abnormal Program termination

Edited 5 Years Ago by Narue: Added code tags

I think the problem was the scanf function you were using to read the floating point number. scanf becomes a little bit upset if it doesn't get what it wants.Also use fgets instead of gets if you want to avoid another "segmentation fault" error.

#include <stdio.h>
#include <stdlib.h>
typedef struct cricket{
	char name[20];
	float avg;
	}cri;

int main(void)
{
cri c[3];
int i;
char temp[10];
for(i=0;i<3;i++){
	printf("\n Entr name :");
	fflush(stdout);
	fgets(c[i].name,sizeof(c[i].name),stdin);

	printf("\n Enter his batting average:");
	fflush(stdout);
	fgets(temp,sizeof(temp),stdin);
	c[i].avg=atof(temp);
}

printf("\n\n Name\tAverage\n\n");

for(i=0;i<3;i++){
	printf("\n%s\t%f",c[i].name,c[i].avg);
}

return 0;
}

Thank you...

(1) so it is like that, we can not read float values directly???

and can u please tell me about these two lines.
extern void float conetor();
#pragma extref floatconnector

it is for reading float value directly and even though i was getting error.

and i've

(2) and i've used fflush(stdin) in this programme.
is that any specific reason to use
fflush(stdout).

Thank you...

(1) so it is like that, we can not read float values directly???

and can u please tell me about these two lines.
extern void float conetor();
#pragma extref floatconnector

it is for reading float value directly and even though i was getting error.

http://c-faq.com/fp/fpnotlinked.html

(2) and i've used fflush(stdin) in this programme.
is that any specific reason to use
fflush(stdout).

fflush(stdin) is wrong, do not use it. fflush(stdout) accomplishes the goal of ensuring that a user prompt shows up before subsequent requests for input begin blocking.

Edited 5 Years Ago by Narue: n/a

This article has been dead for over six months. Start a new discussion instead.