title: C Check all occurrences of a letter appear before another letter
body: <p>So i have a string S consisting of N letters 'a' or 'b'.
  This should return 1 if all occurrences of A are before all occurrences of b and return 0 otherwise.</p>
  <p>B does not need to occur in S and A does not need to occur in S</p>
  <p>For example</p>
  <pre><code>S='aabbb' returns 1 
  S = 'ba' returns 0
  S = 'aaa' returns 1
  S= 'b' returns 1
  </code></pre>
  <p>So my approach was to use a for loop on the string and check if b occurs before a or not like so:</p>
  <pre><code>char newstr[10] = &quot;aabbba&quot;; //should return 0
  
  
  int len = strlen(newstr);
  
  for (int i = 0; i &lt; len+1; i++) {
      printf(&quot;%c&quot;, newstr[i]);
      if (newstr[i] &lt; 'b') {
          printf(&quot;1&quot;);
      }
      else {
          printf(&quot;0&quot;);
      }
  
  }
  </code></pre>
  <p>Output is <code>a1a1b0b0b0a1 1</code> So..it is partially detecting if a is before b but not to its fully correct manner.</p>