hi I wonder if array can be work along with structure?
Below are the declaration of my structure
struct employee{
char ID[15];
char Name[20];
char Department[5][30];
int selection;
char Post[3][30];
};
struct employee record[200];
I was wondering could if there is anywhere you can :
struct employee{
char ID[15];
char Name[20];
char Department[5][30]={"Accounting", "Administration ","Management", "Human
resource","Othe rs"};
int selection;
char Post[3][30];
};
struct employee record[200];
because the problem is when I wanted to store this data , below is the
declaration of arrays within the add_record function
char Department[5][30]={"Accounting", "Administration ","Management", "Human
Resource","Othe rs"};
Here i use to capture the inputs and department as selection :
printf("\n\n 0) %s\n 1) %s\n 2) %s\n 3) %s\n\n [Enter Department for this
new employee]: ", Department[0], Department[1], Department[2],
Department[3]);
fflush(stdin);
scanf("%d", &selection);
if((selection != 0) && (selection != 1) && (selection !=2) && (selection
!=3)) {gotoxy(1, 24); printf(" >>invalid Department<< Retry!\a");}
} while(selection < 0 || selection > 3);
clrscr();
printf("\n Enter The new ID for this employee: ");
fflush(stdin);
gets(ID);
printf("\n Employee Name : ");
fflush(stdin);
gets(Name);
You can only display the contents such as Accounting, Administration when
you printf as Department[selection]
But how should I do if i want it "for example Management" to store in the
structure so that next time when I printf Department for that particular
record in other function it would appear as Management and not blank
because mine when I printf it on other function it is null? The Name, Post
and ID works out fine but the Department cannot stored in the structure as
selection. 2 2449
I am not sure why you want to store all 5 departments in each
employee. Structs can definetly contain arrays. But this data is
static. There is no need for this in each employee. Just the choice
of department is enough
On Wed, 27 Oct 2004 06:41:29 -0400, "kimimaro"
<li************ @yahoo.com> wrote: hi I wonder if array can be work along with structure?
Yes, a member of a structure may be an array.
Below are the declaration of my structure struct employee{ char ID[15]; char Name[20]; char Department[5][30]; int selection; char Post[3][30]; }; struct employee record[200];
This all appears syntactically correct.
I was wondering could if there is anywhere you can :
struct employee{ char ID[15]; char Name[20]; char Department[5][30]={"Accounting", "Administration ","Management", "Human resource","Oth ers"}; int selection; char Post[3][30]; };
You cannot specify the initialization in the *declaration* of the
struct type. You can only specify initialization in the *definition*
of an object with that type.
struct employee record[200];
To be consistent with the intent of the above declaration, you would
use something like
struct employee record[200] = {
{ /* the values for record[0] */ },
{ /* the values for record[1] */ },
............... .. /* sample values for record[i] */
{ "123456789abcde ", /* init value for ID */
"abcdefghijklmn opqrs", /* init value for Name */
{"Accounting ",
"Administration ",
"Management ",
"Human resource",
"Others"}, /* init values for Department */
12, /* init value for selection */
{"post 1",
"post 2",
"post 3"}}, /* init values for Post */
.......... /* as many more sets of init values as you like */
}
because the problem is when I wanted to store this data , below is the declaration of arrays within the add_record function
char Department[5][30]={"Accounting", "Administration ","Management", "Human Resource","Oth ers"};
Here i use to capture the inputs and department as selection :
printf("\n\n 0) %s\n 1) %s\n 2) %s\n 3) %s\n\n [Enter Department for this new employee]: ", Department[0], Department[1], Department[2], Department[3]); fflush(stdin );
fflush is not defined for input streams.
scanf("%d", &selection); if((selectio n != 0) && (selection != 1) && (selection !=2) && (selection !=3)) {gotoxy(1, 24); printf(" >>invalid Department<< Retry!\a");}
Make life easy on yourself. Simply check for outside the desired
range.
} while(selection < 0 || selection > 3);
Just like you did here.
clrscr(); printf("\n Enter The new ID for this employee: "); fflush(stdin ); gets(ID);
gets used this way cannot prevent overrun if the user enters too many
characters.
printf("\n Employee Name : "); fflush(stdin ); gets(Name);
You can only display the contents such as Accounting, Administration when you printf as Department[selection]
But how should I do if i want it "for example Management" to store in the structure so that next time when I printf Department for that particular record in other function it would appear as Management and not blank because mine when I printf it on other function it is null? The Name, Post and ID works out fine but the Department cannot stored in the structure as selection.
Your structure already stores all possible departments for each
element of the array so you need to rethink the question.
<<Remove the del for email>> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kaptain524 |
last post by:
Hello,
I am using PHP 5.0.4 with Apache 2, on WinXP Pro. This behavior
appears to be fundamental however, and should not be affected by
platform.
It would seem that there is some kind of bug in the process that
creates the reference when it is being assigned to an array element
within itself. If it is already referenced, it just...
|
by: Treetop |
last post by:
I cannot get this array to work. I want to have the game listed until the
day after the event, then come off the list.
function events() {
var today = new Date();
var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec
|
by: Neo |
last post by:
Dear All,
I want to know how a subroutine should return an array of values to
the main program.
From the main program, I call a sub-routine 'get_sql' which then
fetches data from oracle db using oci8 routines. The output resides in
a structure defined within the sub-routine. Now I want this structure
to be returned to main program so that I...
|
by: Ben |
last post by:
my program keep crashing itself it executes a structure with static array
members such as this:
module myModule:
.....
structure myStructure
.....
<VBFixedArray(8)> dim myArray() As Single
....
end structure
|
by: ulyses |
last post by:
I'm trying to put pointer to flexible array of structures in other
structure. I want to have pointer to array of pixels in screen
structure. Here is mine code, but I think it isn't quite all right:
struct pixel
{
int x;
int y;
int color;
};
| |
by: bowlderster |
last post by:
Hello,all.
I want to get the array size in a function, and the array is an argument of the function.
I try the following code.
/***************************************
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
|
by: bernd |
last post by:
Hi folks,
a simple question for the experts, I guess.
Obviously I am doing something wrong when trying to access an element
of an array declared within a structure:
#include <stdio.h>
#include <stddef.h>
|
by: O.B. |
last post by:
When using Marshal to copy data from a byte array to the structure
below, only the first byte of the "other" array is getting copied from
the original byte array. What do I need to specify to get
Marshal.PtrToStructure to copy the all the data into the "other"
array?
unsafe public struct DeadReckoning
{
|
by: ctj951 |
last post by:
I have a very specific question about a language issue that I was
hoping to get an answer to. If you allocate a structure that
contains
an array as a local variable inside a function and return that
structure, is this valid?
As shown in the code below I am allocating the structure in the
function and then returning the structure. I know...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |