Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This syntax is incorrect (I misread the question at first because they look like function declarations, not structure definitions):</p> <pre><code>struct custRec(char[20] name, char[50] address, char[20] city, char[2] stateAbbreviation, int zipCode, float balance); struct linkedRec(custRec storedRec, custRec* nextRec, custRec* prevRec); </code></pre> <p>You probably meant:</p> <pre><code>typedef struct custRec { char name[20]; char address[50]; char city[20]; char stateAbbreviation[2]; int zipCode; float balance; } custRec; // Necessary because question is about C, not C++ typedef struct linkedRec { custRec storedRec; custRec *nextRec; custRec *prevRec; } linkedRec; </code></pre> <p>I note that in the US, state abbreviations are 2 characters, so you probably need to use <code>char state[3]</code> to allow for the terminating null.</p> <p>This is now syntactically valid. When you copy data into the fields of the <code>custRec</code>, you will need to be careful to ensure that your copying does not overflow the bounds. The compiler does not enforce the lengths.</p> <p>You will need to check, therefore, inside the function that the strings passed to you do not exceed the limits you expect.</p> <p>If you prefer not to impose limits on the lengths, all the string structure members can be made into <code>char *</code> and you can dynamically allocate the memory for arbitrary length strings. But that is probably not a good idea for US state abbreviations; there you do want to enforce the '2 characters plus <code>'\0'</code>' limit.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload