hi experts,
i have some prob with my code.first,i want to query data from file in string.such as this file "constraint.txt".in this file,i have this:
a1,b2,c1,
a2,b1,c2,
a2,b2,c1,
a3,b1,c2,
i open th file by using this code:
char const_file[100]="constraint.txt";
FILE *in_const[100];
if ((in_const = fopen(const_file, "rt")) == NULL)
{
fprintf(stderr, "Cannot open constraints file.\n");
getch();
exit(0);
}
then,i use this code to load the data into an array and compare to the string append_test_data(for example:a2,b1,c3..this variable will b change everytime we run d code) :
char constraint[MAX_PARAMETER]="";
int id_const=0;
fseek(in_const,0,SEEK_END);// seek from end of file
fseek(in_const,0,SEEK_SET); //seek from begining of file
while(!feof(in_const) )
{
fgets(constraint,500,in_const);
id_const++;
printf("number of constraints=%d\n",id_const);
for (int m=1;m <= id_const;m++)
{
if(strcmp(append_test_data,constraint) == 0)
{
printf("constraint is found=%s\n",constraint);
printf("Append data is=%s\n",append_test_data);
getch();
exit(0);
}
}
}
i got the result but its juz compare with the last data from file.in this example a3,b1,c2,.what i want is append_teast_data will compare to all the data in the file,but looks like it jus compare to the last 1.
im sorry with my language.hopefully u guys can help me since it is my homework and im searching it for weeks.....please!