Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <code>scanf()</code> function needed to be edited<br> from <code>scanf("%s", &amp;response);</code><br> to <code>scanf("%s", response);</code>.<br> That will fix part of the problem. </p> <p>Since you do not want to use globals, why can you not put another argument in </p> <p><code>char *user_string(char *Setting_Type[], char *response_string)</code> ? </p> <p>You would have to allocate memory for it, and free it in the calling function (<code>main()</code>), but it would work in this scenario. (really should be providing some memory for it anyway, in its current usage) </p> <p><em><strong>Example:</em></strong> [Tested, works] </p> <pre><code>#include &lt;ansi_c.h&gt; #include &lt;stdio.h&gt; #include &lt;string.h&gt; char *user_string(char *Setting_Type[], char *s); int main() { char *response; char *test_names[2] = {"Test", "test"}; char *resp; resp = malloc(80);//I picked 80, you can pick something more appropriate response = malloc(80);//I picked 80, you can pick something more appropriate printf("Enter \"Test\" or \"test\": "); //user_string() returns a char *, so just call it in printf() printf("\nCorrect! Your input is: %s\n", user_string(test_names, response)); free(resp); free(response); return 0; } char *user_string(char *Setting_Type[], char *response_string) { int loop = 1; char response[10]; while(loop == 1) { scanf("%s", response); //removed &amp; strcpy(response_string,response);//changed from `=` to `strcpy()` if(strcmp(response_string, Setting_Type[0]) != 0 &amp;&amp; strcmp(response_string, Setting_Type[1]) != 0) printf("\nWrong! Please try again: "); else break; } return response_string; } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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