When i run my program, i get the following:
"Exiting due to signal SIGSEGV
General Protection Fault at eip=0001cdc0
eax=00000009 ebx=000ca110 ecx=000ca110 edx=00000000 esi=0000160e
edi=00000009 ebp=000c99f8 esp=000c99e0 program=C:\TEST.EXE
cs: sel=01a7 base=029d0000 limit=000dffff
ds: sel=01af base=029d0000 limit=000dffff
es: sel=01af base=029d0000 limit=000dffff
fs: sel=017f base=00006ca0 limit=0000ffff
gs: sel=01bf base=00000000 limit=0010ffff
ss: sel=01af base=029d0000 limit=000dffff
App stack: [000c9aac..00049aac] Excetn stack: [00049a00..00047ac0]
Call frame traceback EIPs:
0x0001cdc0
0x0001c46e
0x00001757
0x00005548
"
here is the code i have compiled
#include<stdio.h>
struct pattern
{
char type_of_constraint[50];
char relation[500];
char relation_attribute[50];
char subject[50];
char subject_with[50];
char subject_to[50];
char subject_of[50];
char subject_in[50];
char subject_for[50];
char object[50];
char object_with[50];
char object_to[50];
char object_of[50];
char object_in[50];
char object_for[50];
}a;
FILE *fp1,*fp2;
main(int argc,char *argv[])
{
void Set_must_constraints(char*,char*,char*);
char str[100],b[10][40];
int i,j,k,count,t;
fp1=fopen(argv[1],"r");
if(fp1==NULL)
{
printf("%s : File not found\n",argv[1]);
return 1;
}
fp2=fopen("pattern.dat","wb");
if(fp2==NULL)
{
printf("%s : File not found\n","pattern.dat");
return 1;
}
t=LoadFile(fp1,str);
while(t==1)
{
for(i=j=k=0;str[i];++i)
{
if( (str[i]!=' ' && str[i+1]==' ') || (str[i]!='\t' &&
str[i+1]=='\t') ||
(str[i]!='\n' && str[i+1]=='\n') )
{
b[j][k]=str[i];
++k;
++i;
b[j][k]='\0';
k=0;
++j;
}
else
{
b[j][k]=str[i];
++k;
}
}
b[j][k]='\0';
if( strcmp("must",b[2])==0 && strcmp("have",b[3])==1 )
{
if( strcmp("functions",b[1])==0 && strcmp("single_exit",b[4])==0
)
{
strcpy(a.type_of_constraint,"Dataflow");
Set_must_constraints(b[3],b[1],b[4]);
}
}
t=LoadFile(fp1,str);
}
fclose(fp1);
fclose(fp2);
return 0;
}
int LoadFile(FILE *fp,char x[])
{
int s;
for(s=0,x[s]=getc(fp);feof(fp)!=1;++s,x[s]=getc(fp))
{
if(x[s]=='\n')
{
x[s]='\0';
return 1;
}
}
return 0;
}
/* All X must have Y
1. All CLASSES must have DEFAULT_CONSTRUCTOR
2. All CONDITIONAL_EXPRESSIONS must have EXPLICIT_COMPARISON
3. All IF_STATEMENTS must have ELSE
4. All FUNCTIONS must have EXPLICIT_RETURN_TYPE
5. All FUNCTIONS must have SINGLE_EXIT
*/
void Set_must_constraints(char *rel,char *s_in,char *obj)
{
strcpy(a.relation,rel);
strcpy(a.relation_attribute,"-1");
strcpy(a.subject,s_in);
strcpy(a.subject_with,"-1");
strcpy(a.subject_to,"-1");
strcpy(a.subject_of,"-1");
strcpy(a.subject_in,"-1");
strcpy(a.subject_for,"-1");
strcpy(a.object,obj);
strcpy(a.object_with,"-1");
strcpy(a.object_to,"-1");
strcpy(a.object_of,"-1");
strcpy(a.object_in,"-1");
strcpy(a.object_for,"-1");
fprintf(fp2,"%s %s %s %s %s %s %s %s %s %s %s %s %s %s
%s\n",a.type_of_constraint,a.relation,a.relation_attribute,a.subject,a.subject_with,a.subject_to,a.subject_of,a.subject_in,a.subject_for,a.object,a.object_with,a.object_to,a.object_of,a.object_in,a.object_for);
}


|