title: C++ How to compare strings with pointers ignoring whitespaces?
body: <p>I have to compare 2 char strings... ignoring the whitespaces in it, so e.g:</p>
  
  <pre><code>int cmp("a b c ", "abc") == 0;
  </code></pre>
  
  <p>if both are same , return 0;</p>
  
  <pre><code>else if s1 is bigger than s2, return 1; else return -1; e.g:
  int cmp(" aaab", "aaa") == 1;
  
  int cmp("aaa" , "aa  ab") == -1;
  </code></pre>
  
  <p>how can I realise this with passing the strings as pointers and with pointerarithmetics ?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int strcmp_ign_ws(const char * s1, const char * s2) {
      int count1(0);
      int count2(0);  
  
      while (*s1 != '\0' || *s2 != '\0') {            
  
      if (*s1 == '\0') //if s1 finished, do nothing
      {
          continue;
      }
      if (*s2 == '\0') //if s2 finished, do nothing
      {
          continue;
      }
  
      if ( *s1 == ' ' ) {
          s1++;           //if whitespace, go on to next char
      }
  
      if (*s2 == ' ') {
          s2++;           //if whitespace, go on to next char
      }
  
      if (*s1 == *s2) {  //if same chars, increase counters;go to next char
          s1++;
          s2++;
          count1++;
          count2++;
      }
      if (*s1 &gt; *s2) {
          count1++;
          s1++;
          s2++;
      }
      if (*s1 &lt; *s2) {
          count2++;
          s1++;
          s2++;
      }
      /**
          while (*s1 == *s2) {
              if (*s1 == 0) 
              {
                  return 0;
              }
              s1++;
              count1++;
              s2++;
              count2++;
          }**/
  
  
  }
      return (count1 - count2);
  </code></pre>
  
  <p>}</p>
  
  <p>int main() {</p>
  
  <pre><code>char a[] = "Hallo Welt!!!";
  char b[] = "Hallo Welt";
  
  int result(0);
  
  result = strcmp_ign_ws(a,b);
  
  cout &lt;&lt; result &lt;&lt; endl;
  
  return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>EDIT: I may only use strlen , no other inbuilt functions... or strings</p>