954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Stucture with float values

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?

dev90
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

Can you post your code here?

sergent
Posting Pro
598 posts since Apr 2011
Reputation Points: 70
Solved Threads: 22
 
#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

dev90
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

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;
}
diwakar wagle
Posting Whiz in Training
203 posts since Nov 2008
Reputation Points: 48
Solved Threads: 31
 

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

dev90
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

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

dev90
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 1
 

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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: