Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Structure of Array

This is a discussion on Structure of Array within the C and C++ forums, part of the Software Development category; Hi all, I have written following program which has a array of structures. But it is reading only integer & char values. As soon as it comes to float, it ...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 10-07-2009
Contributing Member
 
Join Date: Aug 2009
Location: bangalore
Posts: 30
Thanks: 11
Thanked 3 Times in 3 Posts
abhi981 is on a distinguished road
Arrow Structure of Array

Hi all,

I have written following program which has a array of structures. But it is reading only integer & char values. As soon as it comes to float, it is not reading & coming out of the program. Can anyone assist me to find the mistake.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct student
{
int id;
char usn[11];
float y;
};
struct student s1[10];
int i,n;
clrscr();
printf("enter value for n=>");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter id=>");
scanf("%d",&s1[i].id);
printf("enter usn=>");
fflush(stdin);
gets(s1[i].usn);
printf("enter float number=>");
scanf("%f",&s1[i].y);
}
for(i=0;i<n;i++)
{
printf("s1===> %10d%20s%10.2f\n",s1[i].id,s1[i].usn,s1[i].y);
}
getch();
}

Thanks & Regards,
Abhijit
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-08-2009
Junior Member
 
Join Date: Mar 2009
Location: COIMBATORE
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
sumitsolution is on a distinguished road
Re: Structure of Array

Hello....
you have to define a function linkfloat() beacuse in majority of compiler floating point format are not linked.....linkfloat() function forces linking of floating_point emultor into an application.......
The given below source code will work..........
********************************************
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct student
{
int id;
char usn[11];
float y;
};
struct student s1[10];
int i,n;
clrscr();
printf("enter value for n=>");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter id=>");
scanf("%d",&s1[i].id);
printf("enter usn=>");
fflush(stdin);
gets(s1[i].usn);
printf("enter float number=>");
scanf("%f",&s1[i].y);
}
for(i=0;i<n;i++)
{
printf("s1===> %10d%20s%10.2f\n",s1[i].id,s1[i].usn,s1[i].y);
}
getch();
}
void linkfloat(){
float a=0,*b;
b=&a;
a=*b;
}
*********************************************************
Sumit Kumar
sumitsolution@gmail.com
Karunya University

Last edited by sumitsolution; 10-08-2009 at 03:47 AM.
Reply With Quote
  #3 (permalink)  
Old 3 Days Ago
Junior Member
 
Join Date: Nov 2009
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pichaiah2009 is on a distinguished road
Re: Structure of Array

Hi,
I had the same problem.After defining the function 'linkfloat' float was accepted.Thanks for the information.
Regards.
Pichaiah
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Structure Padding in C sk_seeker C and C++ 5 11-10-2008 12:08 PM
Database structure of 10g stephen george Oracle 1 01-16-2008 08:16 AM
structure and class jinendrashankar C and C++ 2 12-23-2007 05:46 AM
convert one dimansional array to two dimansional array Geek_Guest C and C++ 6 12-22-2007 04:17 AM
static array or dynamic array? rpgubba C and C++ 6 12-22-2007 04:03 AM


All times are GMT -4. The time now is 12:33 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved