Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,321 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,117 people online right now. Registration is fast and FREE... Join Now!




array structure populating

 
Reply to this topicStart new topic

array structure populating, how to poplulate

lenoy
post 14 Mar, 2008 - 05:01 PM
Post #1


New D.I.C Head

*
Joined: 4 Mar, 2008
Posts: 11



#include <stdlib.h>
#include <stdio.h>


typedef struct{
char fname[10];
char lname[10];
int age[11];
}GUEST;

GUEST guest[50];

void main()
{
int x =0;
printf("please enter guest data : \n");
gets(guest.fname[x]);
x+=1;

}


User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 14 Mar, 2008 - 05:12 PM
Post #2


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


If you know about loops you should be using them or follow this link to understand more about them.

http://www.dreamincode.net/forums/showtopic13919.htm

Here: gets(guest.fname[x]); You want to store a string inside the fname char-array for all the 50 guests.


So the above line should be modified to : gets(guest[x].fname);

Hope this helps !
User is offlineProfile CardPM

Go to the top of the page

lenoy
post 15 Mar, 2008 - 02:52 AM
Post #3


New D.I.C Head

*
Joined: 4 Mar, 2008
Posts: 11

QUOTE(letthecolorsrumble @ 14 Mar, 2008 - 06:12 PM) *

If you know about loops you should be using them or follow this link to understand more about them.

http://www.dreamincode.net/forums/showtopic13919.htm

Here: gets(guest.fname[x]); You want to store a string inside the fname char-array for all the 50 guests.


So the above line should be modified to : gets(guest[x].fname);

Hope this helps !



thanks alot it works
User is offlineProfile CardPM

Go to the top of the page

venke.mv
post 15 Mar, 2008 - 08:58 AM
Post #4


New D.I.C Head

*
Joined: 22 Dec, 2007
Posts: 14

You have to do 2 changes.

1. Put for loop. for(i=0;i<=50;i++)

2. Also, change it as guest[x].fname
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 02:35AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month