Alternating Characters

  • + 0 comments

    C Solution :

    int alternatingCharacters(char* s) {
        int i=0,j,count=0;
        while(s[i]!='\0'){
        char ch = s[i];
        j=i+1;
        while(s[j]==s[i] && s[j]!='\0'){
            j++;
            i++;
            count++;
        }
        if(s[j]=='\0')
            break;
        i++;
      }
      return count;
    }