Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. int str_compare(char first[], char second[])
  7. {
  8. int i = 0;
  9. int key = 0;
  10. char first_char, second_char;
  11.  
  12.  
  13. if (strlen(first) != strlen(second))
  14. {
  15. key = -1;
  16. return key;
  17. }
  18. for (; i < (int)strlen(first); i++)
  19. {
  20. if (!((first[i] >= 97) && (second[i] >= 97)))
  21. {
  22. if ((first[i] >= 97) && (first[i] <= 122))
  23. first_char = first[i] - 32;
  24. else
  25. first_char = first[i];
  26. if ((second[i] >= 97) && (second[i] <= 122))
  27. second_char = second[i] - 32;
  28. else
  29. second_char = second[i];
  30. }
  31. else
  32. {
  33. first_char = first[i];
  34. second_char = second[i];
  35. }
  36.  
  37. if (first_char != second_char)
  38. {
  39. key = -1;
  40. return key;
  41. }
  42. }
  43.  
  44. return key;
  45. }
  46.  
  47. int main()
  48. {
  49. char string[100];
  50. char slovo[100];
  51. char*h;
  52. int counter = 0;
  53.  
  54. gets(string);
  55. gets(slovo);
  56. h = string;
  57. h = strtok(h, " ");
  58. while (h != NULL)
  59. {
  60. if (!str_compare(h, slovo))
  61. counter++;
  62. h = strtok(NULL, " ");
  63. }
  64.  
  65. printf("%d", counter);
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement