Advertisement
EWTD

Untitled

Oct 20th, 2020
2,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. int strdiff(char *a, char *b){
  2.     int index = 0;
  3.     while(a[index] != '\0' && b[index] != '\0' && a[index] == b[index]){
  4.         index++;
  5.     }
  6.    
  7.     if(a[index] == '\0' && b[index] == '\0'){
  8.         return -1;
  9.     }
  10.     char val = a[index]^b[index];
  11.     int i = 0;
  12.     while(val){
  13.         if(val&1){
  14.             return 8*index+i;
  15.         }
  16.         val = val >> 1;
  17.         i++;
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement