Advertisement
STANAANDREY

upper_sub_string

Nov 23rd, 2022 (edited)
10,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define NMAX 1000
  6. #define SSMAX 30
  7.  
  8. uint32_t upper_sub_string(char *str, const char *substr) {
  9.   uint32_t cnt = 0;
  10.   const int lenSS = strlen(substr);
  11.   char *p = strstr(str, substr);
  12.   while (p != NULL) {
  13.     for (int i = 0; i < lenSS; i++) {
  14.       *(p + i) = toupper(*(p + i));
  15.     }
  16.     cnt++;
  17.     p = strstr(p + 1, substr);
  18.   }
  19.   return cnt;
  20. }
  21.  
  22. int main(void) {
  23.   char s1[NMAX], s2[SSMAX];
  24.   fgets(s1, NMAX, stdin);
  25.   fgets(s2, SSMAX, stdin);
  26.   s2[strlen(s2) - 1] = 0;
  27.   printf("%d\n", upper_sub_string(s1, s2));
  28.   puts(s1);
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement