-
Structures, please help.
Hello all.
I have a task for a programming lab which is really confusing me. What I don't understand is how I can-
1. Save the array of Transistor structures into the Stock structure, and;
2. How I can then read and print the values for the ID, polarity, power etc. from the Stock structure.
The question is...
The following code segment defines a C structure that is used to store details of a transistor that we have in stock (manufacturer’s ID, polarity (NPN or PNP), power (maximum power dissipation), current gain and the number of transistors we have in stock). It is assumed that the maximum number of different transistors
is MAXSTOCKITEMS (=10), the maximum length of the manufacturer’s ID is IDLEN (=10) and the length of the polarity is POLARITYLEN (=3). Details of all of the transistors in stock are stored in the second structure.
const int IDLEN=30;
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
struct TransistorRec {
char manufacturersID[IDLEN];
char polarity[POLARITYLEN];
float power;
float gain;
int stock;
;{
typedef struct TransistorRec Transistor;
struct StockRec{
int size;
Transistor stocklist[MAXSTOCKITEMS];
;{
typedef struct StockRec Stock;
Thanks!
-
Interesting - did you delete all the closing braces to get out of using [code][/code] tags?
Did you read the "posting code - read this first" post at the top of the forum?
-
Little bit simpler:
Code:
const int IDLEN=30;
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
typedef struct {
char manufacturersID[IDLEN];
char polarity[POLARITYLEN];
float power;
float gain;
int stock;
} Transistor;
Transistor stocklist[MAXSTOCKITEMS];