SHARE
TWEET

Untitled

razvanth21 Jan 18th, 2017 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(void)
  6. {
  7.     int i = 0, j = 1;
  8.     char s[100], *a, *aux, *p, c;
  9.     FILE *f;
  10.  
  11.     f = fopen("test.txt", "w");
  12.     if (f == NULL)
  13.         exit(1);
  14.  
  15.     while((c = getchar()) != EOF)
  16.         putc(c, f);
  17.  
  18.     fclose(f);
  19.  
  20.     f = fopen("test.txt", "r");
  21.     fread(s, sizeof(char), 100, f);
  22.     fclose(f);
  23.  
  24.     printf("\n%s\n", s);
  25.  
  26.     a = (char *) malloc(1);
  27.     if (!a)
  28.         exit(1);
  29.  
  30.     a[0] = 0;
  31.  
  32.     while ((c = getchar()) != '\n')
  33.     {
  34.         aux = (char *) realloc(a, i + 2);
  35.  
  36.         if (!aux)
  37.         {
  38.             free(a);
  39.             exit(1);
  40.         }
  41.         else
  42.             a = aux;
  43.  
  44.         a[i] = c;
  45.         a[i + 1] = 0;
  46.  
  47.         i ++;
  48.     }
  49.  
  50.     p = strtok(s, "\n");
  51.     while (p != NULL)
  52.     {
  53.         if (strstr(p, a) != NULL)
  54.             printf("%d ", j);
  55.  
  56.         j ++;
  57.         p = strtok(NULL, "\n");
  58.     }
  59.  
  60.     free(a);
  61.     return 0;
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top