Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <mm_malloc.h>
  3.  
  4. int main() {
  5.  
  6.     int length = 0, counter = 0;
  7.     char* str;
  8.  
  9.     puts("Input word length: ");
  10.     scanf("%d", &length);
  11.  
  12.     str = (char*)malloc(length * sizeof(char));
  13.  
  14.     for(int i = 0; i <= length; i++){
  15.         scanf("%c", &str[i]);
  16.     }
  17.  
  18.     for(int i = 0; i <= length; i++){
  19.         if(*str == 'e' && *(str+1) == 'd'){ // если вместо разименовывания написать str[i] == 'e' .... str[i+1] то все норм
  20.                                             // считает в counter
  21.             counter++;
  22.         }
  23.     }
  24.  
  25.     printf("Count of (ed or ED): %d", counter);
  26.     free(str);
  27.     return 0;
  28. }
  29.  
  30. /*
  31. Input word length:
  32. 5
  33. edaed
  34. Count of (ed or ED): 0      // а должно выводить 2 (то есть  ed 2 раза встречается)
  35. Process finished with exit code 0
  36.  
  37. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement