Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck Structure, add items if not already in structure. C
    text
    copied!<p>I'm trying to do some practice programming and I've come to a, for me, a difficult problem.</p> <p>The problem is I'm supposed to write a program the will take the make and model of a car that was "entered" and place it in the structure, if the make an model are not there, otherwise it does nothing.</p> <p>This is what I have so far, and I keep getting errors:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; void addCar(struct car u, int* count, char *make[], char *model[]); struct car { char make[30]; char model[30]; }; int main(void) { struct car unique[10] = {{"Ford", "Explorer"}, {"Honda", "Civic"}, {"Honda", "Accord"}, {"Chevy", "Malibu"}}; int i, count = 4; addCar(unique, &amp;count, "Ford", "Mustang"); } void addCar(struct car u, int* count, char *make[], char *model[]) { } </code></pre> <p>The line that says <code>addCar(unique, &amp;count,...</code> it's saying "Argument type '<code>struct car'</code> is incomplete" and the last line says <strong>"conflicting types for addCar</strong>"</p> <p>Could you all give me a few pointers, please?</p> <p>EDIT:</p> <p>Okay, here is what my code is now, but I still can't get it to work. Any other suggestions would be appreciated!</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; struct car { char make[30]; char model[30]; }; void addCar(struct car *u, int *count, char *make, char *model); int main(void) { struct car unique[10] = {{"Ford", "Explorer"}, {"Honda", "Civic"}, {"Honda", "Accord"}, {"Chevy", "Malibu"}}; int i, count = 4; printf("%s", unique[0].make); addCar(unique, &amp;count, "Ford", "Mustang"); } void addCar(struct car *u, int *count, char *make, char *model) { int i = 0; for (i; i &lt; *count; i++) { if ((u[i].make != make) &amp;&amp; (u[i].model != model)) { strcpy(u-&gt;make, make); strcpy(u-&gt;model, model); count++; } } for (i = 0; i &lt; *count; i++) printf("%s, %s", u[i].make, u[i].model); } </code></pre>
 

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