Note that there are some explanatory texts on larger screens.

plurals
  1. POUnititialized structure definition
    primarykey
    data
    text
    <p>I am having trouble with structure definitions. I understand the syntax but can't use it correctly to make a working program. My assignment is to define a structure type <code>element_t</code> to represent one of the elements of the periodic table. Components should include atomic number, name, symbol, class, weight and a seven element array of integers for the number of electrons in each shell. The following are the components of an <code>element_t</code> structure for sodium.</p> <pre><code>11 Sodium Na alkali_metal 22.9898 2 8 1 0 0 0 0 </code></pre> <p>Define and test I/O functions <code>scan_element</code> and <code>print_element</code>. Here is my code... but no worky. I dont understand why the compiler says I haven't initialized element_t. Thanks in advance.</p> <p>***Ended up with the following code, also added the appropriate loops and &amp; signs although it is not shown below and everything worked fine. I was curious to know how the powerpoint slides in my class used {2 8 1 0 0 0 0} to populate the int array instead of a loop. The book I am using uses the loop method as well but I wanted to try the {} way of doing it. Thanks again.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; typedef struct { int atomic_num; char* element_name; revised: char element_name[25]; char* element_symbol; revised: element_symbol[2]; char* element_class; revised: char element_class[25]; double atomic_weight; int electrons[7]; } element_t; int scan_element(); revised: element_t scan_element(); void print_element(element_t my_element); int scan_element() { element_t my_element; printf("Enter Atomic Number&gt; "); scanf("%d", my_element.atomic_num); printf("Enter Element Name&gt; "); scanf("%s", my_element.element_name); printf("Enter Element Symbol&gt; "); scanf("%s", my_element.element_symbol); printf("Enter Element Class&gt; "); scanf("%s", my_element.element_class); printf("Enter Atomic Weight&gt; "); scanf("%lf", my_element.atomic_weight); printf("Enter Electons in each shell&gt; "); scanf("%d", my_element.electrons); print_element(my_element); return 0; } void print_element(element_t my_element) { printf("%d %s %s %s %lf %d \n",my_element.atomic_num,my_element.element_name, my_element.element_symbol,my_element.element_class,my_element.atomic_weight,&amp;my_element.electrons); } int main() { scan_element(); revised: print_element(scan_element()); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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