Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "string.h"
  4.  
  5. #define COL 128
  6. #define LEN 128
  7.  
  8. int strend(char *, char*);
  9.  
  10. int main(int argc, char* argv[])
  11. {
  12.     char arr[COL][LEN];
  13.     int i = 0;
  14.     if (argv[1]) {
  15.         //выход по EOF
  16.         printf("%s\n", "Введите строки, в которых будем искать:");
  17.         while (fgets(arr[i], LEN, stdin) != NULL){
  18.             i++;
  19.         }
  20.         for (int j = 0; j < i; j++) {
  21.             if (strend(arr[j], argv[1]) == 1) {
  22.                 printf("Строка подходит: %s", arr[j]);
  23.             }
  24.         }
  25.  
  26.     } else{
  27.         printf("%s", "Введите шаблон через консоль");
  28.         return 1;
  29.     }
  30.  
  31.     return 0;
  32. }
  33.  
  34. int strend(char *str, char *temp){
  35.     int temp_len = (int)strlen(temp);
  36.     int str_len = (int)strlen(str);
  37.     char str1[LEN];
  38.     int j = 0;
  39.     if (strlen(str) >= strlen(temp)){
  40.         for (int i = str_len - temp_len - 1; i < str_len; i++){
  41.             str1[j] = str[i];
  42.             j++;
  43.         }
  44.         str1[j-1] = '\0';
  45.         if(strcmp(str1, temp) == 0){
  46.             return 1;
  47.         } else
  48.             return 0;
  49.     } else
  50.         return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement