Note that there are some explanatory texts on larger screens.

plurals
  1. POC: passing arrays to another method properly
    primarykey
    data
    text
    <pre><code>/* * PURPOSE * Search if a string contains a string and print it out from there */ #include &lt;stdio.h&gt; void searchHaystack(char cHaystack[], char cNeedle[]); void showResult(int iOffset, char cHaystack[]); int main() { // Declarations char cHaystack[50], cNeedle[50]; // Input puts("Haystack:"); gets(cHaystack); puts("Needle:"); gets(cNeedle); // Call searcher searchHaystack(cHaystack, cNeedle); return 0; } void searchHaystack(char cHaystack[], char cNeedle[]) { // Declarations int iCntr, iCntr2, iFoundOffset; // Search the haystack for the first letter of the needle for (iCntr == 0; iCntr &lt; 50 &amp;&amp; cHaystack[iCntr] != '\0'; iCntr++) { if (cHaystack[iCntr] == cNeedle[0]) { iFoundOffset = iCntr; for (iCntr2 == 1; iCntr2 &lt; 50 &amp;&amp; (cHaystack[iCntr+iCntr2] == cNeedle[iCntr2] || cNeedle[iCntr2] == '\0'); iCntr2++) { if (cNeedle[iCntr2] == '\0') { showResult(iFoundOffset, cHaystack); } } } } } void showResult(int iOffset, char cHaystack[]) { int iCntr; // Print the substring char by char for (iCntr == iOffset; iCntr &lt; 50 &amp;&amp; cHaystack[iCntr] != '\0'; iCntr++) { printf("%c", cHaystack[iCntr]); } printf("\n"); } </code></pre> <p>Looking at my debugger I noticed that cHaystack[] and cNeedle[] aren't passed to searchHaystack properly as only the first char is conserved. How do I fix this? I haven't learned about pointers yet.</p> <p>Also, I'm getting this warning on all three for loops:</p> <blockquote> <p>statement with no effect</p> </blockquote> <p>What's up with that?</p>
    singulars
    1. This table or related slice is empty.
    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