#Circuits and nodes

6 messages · Page 1 of 1 (latest)

twilit lintel
#

I am not sure whether this is the right code i should right

viral gullBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

#

@twilit lintel

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

twilit lintel
#
typedef enum {
    resistor,
    voltage,
    current
} CompType;

typedef struct {
    char* name;
    unsigned int n1;
    unsigned int n2;
    double value;
    CompType type;
} Component;

typedef struct {
    unsigned int nC;
    unsigned int nR;
    unsigned int nV;
    unsigned int nI;
    unsigned int nN;
    Component* comp;
} Circuit;
#
    for(c.nC=0; fscanf(fPtr, "%s %u %u %lf", c.comp[c.nC].name, &c.comp[c.nC].n1, &c.comp[c.nC].n2, &c.comp[c.nC].value) == 4; c.nC++) {
        switch(c.comp[c.nC].name[0]) {
            case 'R': c.nR++; c.comp[c.nC].type = resistor; break;
            case 'V': c.nV++; c.comp[c.nC].type = voltage; break;
            case 'I': c.nI++; c.comp[c.nC].type = current; break;
            default: fprintf(stderr, "Unknown component on line %u in file %s.\n", c.nC + 1, filename); exit(EXIT_FAILURE);
        }
        if (c.comp[c.nC].n1 > c.nN) c.nN = c.comp[c.nC].n1;
        if (c.comp[c.nC].n2 > c.nN) c.nN = c.comp[c.nC].n2;
    }

viral gullBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.