Structures, please help.

This is a discussion on Structures, please help. within the C Programming forums, part of the General Programming Boards category; Hello all. I have a task for a programming lab which is really confusing me. What I don't understand is ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    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!

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    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];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with Nested Structures and Arrays of Structures
    By Ignoramus in forum C Programming
    Replies: 4
    Last Post: 03-02-2010, 12:24 AM
  2. Structures and dynamically allocated arrays
    By Bandizzle in forum C Programming
    Replies: 7
    Last Post: 10-04-2009, 02:05 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. Classes and Structures.
    By jrahhali in forum C++ Programming
    Replies: 6
    Last Post: 03-28-2004, 04:03 PM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21