Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(int argc, char** argv[])
- {
- FILE *fin = fopen(argv[3], "r");
- char strF[10000],line[10000];
- char grep[strlen(argv[2])];
- char str[strlen(argv[2])];
- int i = 0, j = 0;
- if(argv[1] == "-cat")
- {
- while(scanf("%c", &strF[i]) != EOF)
- {
- i++;
- }
- }
- else
- {
- while(fscanf(fin, "%c", &strF[i]) != feof(fin))
- {
- i++;
- }
- }
- strcpy(grep, argv[2]);
- for(i = 0; i < strlen(strF); i++)
- {
- for(j = 0; j < strlen(strF); j++)
- {
- if(strF[j + i] == '\n')
- {
- i += j;
- break;
- }
- else
- {
- line[j] = strF[j + i];
- }
- }
- for(int s = 0; s < strlen(line); s++)
- {
- for(int s1 = 0; s1 < strlen(grep); s1++)
- {
- str[s1] = line[s1 + s];
- }
- if(strncmp(grep, str, strlen(grep)) == 0)
- {
- printf("%s\n", line);
- break;
- }
- }
- memset(line, 0, strlen(line));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement