Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(int argc, char** argv[])
  5. {
  6.     FILE *fin = fopen(argv[3], "r");
  7.     char strF[10000],line[10000];
  8.     char grep[strlen(argv[2])];
  9.     char str[strlen(argv[2])];
  10.     int i = 0, j = 0;
  11.     if(argv[1] == "-cat")
  12.     {
  13.         while(scanf("%c", &strF[i]) != EOF)
  14.         {
  15.             i++;
  16.         }
  17.     }
  18.     else
  19.     {
  20.         while(fscanf(fin, "%c", &strF[i]) != feof(fin))
  21.         {
  22.             i++;
  23.         }
  24.     }
  25.    
  26.     strcpy(grep, argv[2]);
  27.     for(i = 0; i < strlen(strF); i++)
  28.     {
  29.         for(j = 0; j < strlen(strF); j++)
  30.         {
  31.             if(strF[j + i] == '\n')
  32.             {
  33.                 i += j;
  34.                 break;
  35.             }
  36.             else
  37.             {
  38.                 line[j] = strF[j + i];
  39.             }
  40.            
  41.         }
  42.         for(int s = 0; s < strlen(line); s++)
  43.         {
  44.             for(int s1 = 0; s1 < strlen(grep); s1++)
  45.             {
  46.                 str[s1] = line[s1 + s];
  47.             }
  48.             if(strncmp(grep, str, strlen(grep)) == 0)
  49.             {
  50.                 printf("%s\n", line);
  51.                 break;
  52.             }
  53.        
  54.         }
  55.         memset(line, 0, strlen(line));
  56.      }
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement