473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Can't we access float variables in a C structure directly?

Hi I'm prasad.
I am new to structures in C.
I declared a structure as follows.
But it is giving a run-time error that
"scanf: floating point formats not matched
Abnormal program termination
" at the line indicated.
Some of my friends told me that we can't access floating point variables in structures directly. We need the help of certain functions. Is it true? If so how to access them?

#include<stdio.h>
#include<conio.h>
#include<alloc.h>

struct struct1
{
int eno;
char ename[20];
float sal;
};
int main()
{
struct struct1 *p;
clrscr();
p=malloc(sizeof(struct struct1)*1);

printf("Enter employee number: ");
scanf("%d",&(*p).eno);
printf("Enter employee name: ");
scanf("%s",(*p).ename);
printf("Enter employee salary: ");
fflush(stdin);
scanf("%f",&(*p).sal);
printf("NUMBER: %d\n",(*p).eno);
printf("NAME: %s\n",(*p).ename);
printf("SALARY: %0.1f\n",(*p).sal);

return 1;
}

Please help me. Thanks in advance.
Mar 3 '08 #1
4 3006
gpraghuram
1,275 Expert 1GB
I changed the memory allocation line like this
p=(struct struct1*)malloc(sizeof(struct struct1)*1);
and it worked fine without any issues

Raghuram
Mar 4 '08 #2
Hi I have tried that change but it's not working.
Again the same error of 'floating points not linked'
Mar 5 '08 #3
gpraghuram
1,275 Expert 1GB
Hi I have tried that change but it's not working.
Again the same error of 'floating points not linked'
i used gcc compiler in cygwin.
Which compiler u are using?

Raghuram
Mar 6 '08 #4
manjuks
72
i used gcc compiler in cygwin.
Which compiler u are using?

Raghuram
I tried in DEV C++ its working fine. Where as in Turbo C its giving that error. I also don't know why that error is coming.
Mar 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Try Kret | last post by:
Hello ! I was wondering how to create a function that can be applied to all type of variables? If we use for example, sortList(void *obj), we can not do the comparison of 2 strcut. ...
8
by: Fernan Bolando | last post by:
I have been going through some of the tutorials on the internet regarding coding styles in unix C programming. Most of the stuff I have read do not prefer using global variables, But for multi-file...
4
by: hufel | last post by:
Hi, I'm doing my first big project in C# and I'm stuck with a problem that I believe has a simple and efficient solution for it (I just haven't bumped into it yet...). The concept is the...
13
by: COHENMARVIN | last post by:
I want to have an array of structures in my application. Each structure might hold some info, like this: Structure MyStruct FirstName as String LastName as String age as integer End Structure...
16
by: chandanlinster | last post by:
As far as I know floating point variables, that are declared as float follow IEEE format representation (which is 32-bit in size). But chapter1-page no 9 of the book "The C programming language"...
9
by: pkirk25 | last post by:
Hi all, Is there an alternative to writing a set/get function for each data member of a class? For data members that are never changed once the class is initialised it would seem logical you...
12
by: mast2as | last post by:
Hi everyone I am working on some code that uses colors. Until recently this code used colors represented a tree floats (RGB format) but recently changed so colors are now defined as spectrum....
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
10
by: Jim Langston | last post by:
I use a game engine using MSVC++ .net 2003 and have no problems. Some users of DevC++ who use the same engine crash at times when a copy of this structure is the return variable. I don't have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.