wazzup?...i got 4 functions including main (see below)...main gives the option of calling engine() or find()...these 2 call funk() for the computation and printinf of results...find() works fine when it call funk()...so funk() is working alright...engine() with funk() gives a Segmentation Fault core dumped!...engine() is this tinee tiny lil' function with 10 lines of code...can't seem to figure out whats' wrong...tried all sorts of juxtapositioning of code...doesn't seem to solve the problem...would greatly appreciate some inputs...need to sumbit tomm!~
PS: I gotta bad feeling about the file pointers!
#include<stdio.h>
#include<string.h>
int a,b,c,d,y=0,z=0,i=0,j,k,l=0,m,n,ctr=0,len,len1,len 2,len3,len4,len5,len6,len7,len8,len9,len10,f,x,chk =0;
char message[38]="MAIL From:<[email protected]>", cell[5]="9198", cell_1[5]="+919", cell_2[5]="9810", cell_3[5]="9811", cell_4[5]="9821", cell_5[5]="9820", cell_6[5]="9841", cell_7[5]="9823", cell_8[5]="9830";
char line[300];
void funk();
main()
{
char choice;
void engine();
void find();
printf("ENTER 'D' to display the following details from the SMS server log file:\n1. Message Sent Time\n2. Message Sent Date\n3. Customer's Mobile Number\n");
printf("\nOR\n\nEnter 'S' to search records by DATE\n");
scanf("%c",&choice);
if(choice=='D')
engine();
if(choice=='S')
find();
}
void engine()
{
FILE *fp;
fp=fopen("ummailer.txt","r"); //ENTER SMS server log file name here
while(!feof(fp))
{
while(fgets(line,300,fp)!=NULL)
{
funk(line, fp);
label: x=ftell(fp);
fseek(fp,x,0);
}
}
fclose(fp);
}
void find()
{
char input_mth[4];
char input_dt[3];
FILE *fp;
printf("ENTER the search month (e.g. 'Apr'):\n");
scanf("%s",input_mth);
printf("ENTER the search date (e.g. '18'):\n");
scanf("%s",input_dt);
if(strlen(input_dt) == 1)
{d=5;
c=1;}
else
{d=4;
c=2;}
fp=fopen("ummailer.txt","r"); //ENTER SMS server log file name here
while(!feof(fp))
{
while(fgets(line,300,fp)!=NULL)
{
len=strlen(line);
for(i=0;i<3
{
if(line[i]==input_mth[i])
{
i++;
if(i==3)
{
for(n=0;n<c
{
if(line[n+d]==input_dt[n])
{
n++;
if(n==1 && line[4]==' ' && (strlen(input_dt)==1))
{
funk(line, fp);
}
if(n==2 && line[4]!=' ' && (strlen(input_dt)==2))
{
funk(line, fp);
}
}
else goto label;
}
}
}
else break;
}
label: z=ftell(fp);
fseek(fp,z,0);
}
}
fclose(fp);
}
void funk(char * line, FILE *fp)
{
FILE *fp1;
char _line[300];
len=strlen(_line);
fp1=fopen("ummailer.txt","r");
for(j=41;j<77;j++)
{
for(k=0;k<37
{
if(line[j]==message[k])
{
j++;
k++;
if(k==36)
{
ctr++;
printf("RECORD NUMBER: %d\n",ctr);
printf("Message Sent DATE: ");
for(m=0;m<6;m++)
{
printf("%c",line[m]);
}
printf("\n");
printf("Message Sent TIME: ");
for(m=7;m<15;m++)
{
printf("%c",line[m]);
}
printf("\n");
f=ftell(fp);
fseek(fp1,f,0);
while(fgets(_line,300,fp1)!=NULL)
{
len=strlen(_line);
for(a=0;a<len;a++)
{
for(b=0;b<4
{
if(_line[a]==cell_2[b] || _line[a]==cell_1[b] || _line[a]==cell[b] || _line[a]==cell_3[b] || _line[a]==cell_4[b] || _line[a]==cell_5[b] || _line[a]==cell_6[b] || _line[a]==cell_7[b] || _line[a]==cell_8[b])
{
a++;
b++;
len1=strlen(cell);
len3=strlen(cell_1);
len4=strlen(cell_2);
len5=strlen(cell_3);
len6=strlen(cell_4);
len7=strlen(cell_5);
len8=strlen(cell_6);
len9=strlen(cell_7);
len10=strlen(cell_8);
if((b+1)==len1 && _line[a-3]=='9')
{
printf("Mobile Number: ");
for(c=54;c<66;c++)
{
printf("%c",_line[c]);
}
printf("\n");
printf("\n");
goto label;
}
if((b+1)==len3 && _line[a-3]=='+')
{
printf("Mobile Number: ");
for(c=a;c<(a+12);c++)
{
printf("%c",_line[c]);
}
printf("\n");
printf("\n");
goto label;
}
}
else break;
}
}
y=ftell(fp1);
fseek(fp1,y,0);
}
label: fclose(fp1);
}
} //END OF FIRST EVER 'IF'
else
break;
}
}
}