Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1.  
  2.     #include <stdio.h>
  3.     #include <string.h>
  4.     int strcmp1(char *a,char *b,int flag)
  5.     {
  6.     if(strcmp(strstr(a,b),b)==0)
  7.     return 1;
  8.     else
  9.     return flag;
  10.     }
  11.    
  12.  
  13.     main()
  14.     {
  15.     int flag=0,a=0;
  16.     int z=0;
  17.     int i=0,j;
  18.     char w[50];
  19.     char t[20],refer[50];
  20.     char k;
  21.     FILE *f1;
  22.     FILE *f2;
  23.     printf("Enter word:");
  24.     scanf("%s",w);
  25.     f1=fopen("refer.txt","r+");
  26.     f2=fopen("replica.txt","w");
  27.     while(!feof(f1))
  28.     {
  29.     k=getc(f1);
  30.     t[a]=k;
  31.     refer[i]=k;
  32.                 if(k==' ')
  33.                {
  34.                  flag=strcmp1(t,w,flag);
  35.                  for(j=0;j<a;j++)
  36.                  t[j]='\0';
  37.                  a=0;
  38.                }
  39.                 else
  40.                 a++;
  41.           if(k=='\n')
  42.            {             flag=strcmp1(t,w,flag);
  43.                          for(j=0;j<=a;j++)
  44.                          t[j]='\0';
  45.                          a=0;
  46.             if(flag==0)
  47.               {
  48.                 for(j=0;refer[j]!='\n';j++)
  49.                  {
  50.                   fputc(refer[j],f2);
  51.                  }
  52.                  fputc('\n',f2);
  53.               }          
  54.               flag=0;
  55.            for(j=0;refer[j]!='\n';j++)
  56.                {
  57.                 refer[j]='\0';
  58.                }
  59.              i=0;continue;
  60.            }
  61.     i++;
  62.      
  63.     /*if(k=='\n')
  64.     qw++;
  65.     if((k==' ')||(k=='\n')||!(foef(f1++)))
  66.     {
  67.     t[i-1]='\0';
  68.     (strcmp(strstr(t,w),w)==0);
  69.     line[qw]=1;
  70.     while((k=getc(f1))!='\n');*/
  71.      
  72.     }
  73. fclose(f1);fclose(f2);
  74. remove("refer.txt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement