I have a C program that parses a configuration file. The configuration file allows some wildchars in the format
option=%any.
The problem is that when I use strcmp to compare the value, I get an illegal instruction error.
Sample program to illustrate this:
char str1[10];
sprintf(str1,"%any");
if(strcmp(str1,"%any") == 0)
printf("match\n");
return 0;
Output:
$ ./a.out
Illegal instruction
printf also throws this error.
With
printf(“%s\n”,str1);
output is:
$ ./a.out
0x0.07fff00000001p-1022ny
Illegal instruction
I tried escaping, i.e using “\%any” instead of “%any” in sprintf; but this doesn’t help.
In C++, with std::string == comparison, and printing using cout seems to be working fine.
Could some one please help me to find out how to do this with C.
It comes from
sprintf.As Paul R. stated, you can use rather
strcpyto don’t worry about these formats.