Advertisement
Guest User

store matches of symbols in near bite

a guest
Jun 27th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | Source Code | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.  
  5.     int     a[] = {'a','b','c','d','e' /*etc...*/},
  6.             len = 0,
  7.             size = sizeof(a)/sizeof(int);
  8.  
  9.     char str[] = "abscinence";
  10.     char * p;
  11.  
  12.     len = sizeof(str);
  13.  
  14.     for(int i = 0; i < len; i++){
  15.         for(int c = 0; c < size; c++){
  16.  
  17.             p = (char*) &a[c];
  18.  
  19.             if( *p != str[i] ) continue;
  20.  
  21.             p++;
  22.             *p = *p + 1;
  23.  
  24.         }
  25.     }
  26.  
  27.     for(int i = 0; i < size; i++){
  28.  
  29.         p = (char*) &a[i];
  30.         p++;
  31.  
  32.         printf("\'%c\' has %d matches\n",a[i],*p);
  33.     }
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement