I need to read parameters from a file called "params.c", the following is the codes which can read parameters from that file. But I am not totally understand. Hope anyone can give detailed answers. Thanks.
In a file called "params.c" I have:
#include "systems.h" /* it includes all .h codes I need */
int mystrcmp(const char *tag, char *buff)
{
int l = strlen(tag) ;
return( strcmp(tag, buff, l) ) ; /* why he uses 3 parameters? I think it should be 2 parameters in "strcmp" ? */
int params(char *file, int *nx, int *ny)
{
FILE *fd ;
fd = fopen(file,"r") ;
if ( fd == NULL )
{
fprintf(stderr, "cannot open %-s\n",file) ;
return(1) ;
}
while ( fgets(buff,256, fd ) )
{
if ( mystrcmp("nx", buff) == 0 )
sscanf(buff, "%*s %d", nx ); /* what is "%*s" mean? */
if ( mystrcmp("ny", buff) == 0 )
sscanf(buff, "%*s %d", ny );
fclose(fd) ;
return(0) ;
}
}
After I compile it ( I do have main funtion, but the probem is here), it shows:
In function ‘mystrcmp’:
"error: too many arguments to function ‘strcmp’ "
warning: passing argument 1 of ‘fgets’ from incompatible pointer type
warning: passing argument 2 of ‘mystrcmp’ from incompatible pointer type
warning: passing argument 1 of ‘sscanf’ from incompatible pointer type
Thank you in advance.