Wikia

Vim Tips Wiki

Use grep to get a clickable list of function names

Talk0
1,612pages on
this wiki
Revision as of 11:46, August 30, 2011 by 62.189.77.47 (Talk)

         #include<stdio.h>        
         #include<string.h>    
         int main(int argc,char *argv[])
            {	
         	       int i,j;
                    char a1[100],b1[100];
                    FILE *fp;
                    if(argc==3)
                       {
                             fp=fopen(argv[2],"r");
                             strcpy(a1,argv[1]);
                             i=0;
                             while(!feof(fp))
                                 {
                                       fgets(b1,sizeof(b1),fp);
                                       if(strstr(b1,a1)!=NULL)
                                           {
                                                  i++;
                                                  printf("%s",b1);
                                   	 }
                           
                                 }
                             if(i==0)
                                 printf("\n NO MATCH FOUND \n");
             	               fclose(fp);
                       }
                    else if(argc==4)
                       {
                             int i=0;
                             char a[100],b[100],c[100];
                             fp=fopen(argv[3],"r");
                             strcpy(a,argv[2]);
                             if(argv[1][1]=='n')
                                 {
   
                                      j=0;
                                      printf("Lno  Line\n");
                                      while(!feof(fp))
                                          {
                                                  fgets(b,sizeof(b),fp);
                                                  i++;
                                                  if(strstr(b,a)!=NULL)
                                                      {
                                             	       j++;
                                                               printf("%d    %s\n",i,b);
                                                      }
                                          }
                     	          if(j==0)
                                      printf("\nNO MATCH FOUND\n");
                                      fclose(fp);
                                 }
                             if(argv[1][1]=='c')
                                 {
                                      i=0;
                                      j=0;
                                      fp=fopen(argv[3],"r");
                                      while(!feof(fp))
                                          {
                                               fgets(b,sizeof(b),fp);
                                               if(strstr(b,a)!=NULL)
                                               {
                                                  i++;
                                           }
                                  }
                                  printf("\n Number of lines containing Pattern %s is : %d\n",a,i);
                             if(i==0)
                                     printf("NO MATCH FOUND\n");
                             fclose(fp);
     }
                         if(argv[1][1]=='v')
  {
                                i=0;
                                    fp=fopen(argv[3],"r");
                                 while(!feof(fp))
                                   {

fgets(b,sizeof(b),fp); if(strstr(b,a)==NULL)

                                {
                                       i++;
                                          printf("%s",b);
                                     }
                             }
                    if(i==0)
                            printf("\nALL LINES CONTAINS THE PATTERN\n");
   
    fclose(fp);
                         }
                      if(argv[1][1]=='x')
  {
   
   
                          fp=fopen(argv[3],"r");
                                a[strlen(a)]='\n';

i=0;

                              while(!feof(fp))
                                 {
                                          fgets(b,sizeof(b),fp);
                                   if(strcmp(a,b)==0)
                                  {
                                         i++;
                                            printf("%s",b);
                                        }
                              }
                           if(i==0)
                                   printf("\nNO LINE MATCHES THE PATTERN\n");
 fclose(fp);
    }
 if(argv[1][1]=='i')
                  {
            j=0;
 fp=fopen(argv[3],"r");
                    for(i=0;a[i];i++)
 a[i]=tolower(a[i]);
                    while(!feof(fp))
                    {

fgets(b,sizeof(b),fp);

                           for(i=0;b[i];i++)
                                    c[i]=tolower(b[i]);
                                    if(strstr(c,a)!=NULL)
  {
                                         printf("%s",b);
 i++;
                                   }
                  }
                   if(j==0)

printf("\nNO MATCH FOUND\n"); fclose(fp); } } else

 {
                       printf("\nEnter Arguments As Per Grep Command\n ");

}

 return 0;

}

Around Wikia's network

Random Wiki