acobzew

sem4-problem1

Apr 24th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <string.h>
  4. #define MAX_STR_LEN 100
  5. #define MAX_STR_COUNT 100
  6.  
  7. bool strend(char *s, char *end)
  8. {
  9.     int i, j;
  10.     bool isEnd = true;
  11.     for (i = strlen(s), j = strlen(end); i >= 0 && j >= 0 && isEnd; i--, j--)
  12.         isEnd = s[i] == end[j];
  13.     return isEnd;
  14. }
  15.  
  16. int main(int argc, char *argv[])
  17. {
  18.     char s[MAX_STR_COUNT][MAX_STR_LEN], end[MAX_STR_LEN];
  19.     int i = 0, j = 0;
  20.     if (argc > 1)
  21.         strcpy(end, argv[1]);
  22.     else
  23.     {
  24.         printf("Enter template: ");
  25.         scanf("%s", end);
  26.     }
  27.  
  28.     while (scanf("%s", s[i++]) != EOF);
  29.  
  30.     printf("\n");
  31.     for (j = 0; j < i; j++)
  32.         if (strend(s[j], end))
  33.             printf("%s\n", s[j]);
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment