pattern matching program problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunbs84
    New Member
    • Jan 2008
    • 1

    pattern matching program problem

    hi friends this is arun from coimbatore.i had written one program for pattern matching.That is ,the user have one file and after run his c program he pass some text command line, if the text is found in file the line number will be print.but my program checks only first two lines.it will not check other lines.i am trying to find out the prob.plz anybody help me to find wat wrong in my program.
    thanking u.
    the program is:

    [CODE=c]#include<stdio. h>
    #include<stdlib .h>
    #include<string .h>
    main(int x,char *j[])
    {
    int g,h,z=1;
    char ch,c[30]=" ",d[30]=" ",a[30]=" ";
    int n,i=0,line=0;
    FILE *f;
    printf("******* **********FILE NAME IS:%s\n",j[1]);
    f=fopen(j[1],"r");
    if(f!=NULL)
    printf("******* **********FILE OPENED********* *******\n");
    for(n=2;n<x;n++ )
    {
    strcat(c,j[n]);
    if(n!=x-1)
    strcat(c," ");
    }
    strcpy(a,c);
    for(g=0,h=1;a[g]!='\0';g++,h++)
    a[g]=a[h];
    a[g]='\0';
    printf("******* ***********SEAR CH TEXT IS:%s\n",a);
    while((z=feof(f ))==0)
    {
    fseek(f,0,1);
    while((ch=fgetc (f))!='\n')
    i++;
    i=i+2;
    line++;
    fseek(f,-i,1);
    fgets(d,i,f);
    if((strstr(d,a) )!=NULL)
    {
    printf("******* ***********LINE NO IS=>%d :%s\n",line,d);
    }
    else
    {
    printf("******* **********LINE NO IS=>%d\t******* ****NOT FOUND\n",line);
    }
    i=0;
    }
    }[/CODE]
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    I'm sorry that I can't give you an answer to your immediate question, but I suggest you take the time to learn proper indenting. As it is right now, your code is a horrible mess that's hard to decipher. Taking 5 minutes or so to go through it and indent it properly - two or three spaces per block a statement is embedded in - will make your life MUCH easier when you go back to edit it. Better yet, do it while you are coding.

    Comment

    Working...