Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have more problems, or different problems, than what you've told us.</p> <p>In the code you've shown us, the <code>s1</code> and <code>s2</code> parameters are of type <code>char*</code>. The <code>strcmp()</code> function expects arguments of type <code>char*</code> (actually <code>const char*</code>).</p> <p>If you call <code>strcmp(*s1,*s2)</code>, that's an attempt to call <code>strcmp</code> with two arguments of type <code>char</code>. That won't give you incorrect results as you describe; it won't compile. At the very least, your compiler should be complaining about type mismatches.</p> <p>If you don't have a <code>#include</code> for either <code>&lt;string.h&gt;</code> or <code>&lt;cstring&gt;</code>, the header that declares the <code>strcmp</code> function, then it's possible that the compiler won't recognize the mismatch -- but calling an undeclared function is invalid in C++.</p> <p>It's true, as both of the other answers say, that you should be calling <code>strcmp(s1, s2)</code> rather than <code>strcmp(*s1, *s2)</code> -- but that doesn't explain the symptoms you're describing. Correcting the call to <code>strcmp()</code> will not by itself correct all the problems you're having.</p> <p>I can think of a few possible explanations:</p> <ol> <li><p>You're using an old compiler that doesn't complain about calls to undeclared functions. Get a newer compiler, or invoke your compiler with options that make it conform more closely to the language standard.</p></li> <li><p>Your compiler is producing warnings (diagnostics don't have to be fatal) and you're ignoring them. Don't ignore warnings.</p></li> <li><p>For some reason, you've decided to add your own declaration of the <code>strcmp()</code> function, perhaps something like <code>int strcmp(char s1, char s2);</code>. Don't do that. If you need a declaration for a standard function, add a <code>#include</code> directive for the appropriate header.</p></li> </ol>
 

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