fscanf error
hello, I hope someone can help me out as I'm a bit puzzeled by this warning, the warning is
warning: char format, different type arg (arg 3) I get this from the following code static int aseGetGEOMOBJECT(FILE *s) { char data[255]; int count=0; rewind (s); while (!feof (s)) { fscanf(s, "%s", &data); THIS IS ERROR if (!strcmp (data,"*GEOMOBJECT")) count++; } printf("number of objects %d\n",count); return(count); } Thanks :) |
as you probably know, fscanf wants a character pointer for arg3, but you are passing it a pointer to a character pointer...so the compiler throws a warning.
just use 'data' and omit the '&'. in C, an array name by itself is an address (i.e. pointer) to the first element of the array. so in essense, '&data' is the address of the pointer. instead, you just want the pointer of itself. alternatively, you could do '&data[0]'. |
you are generally better off, IMHO,
for non-trivial programs, in reading the input as one string (fgets maybe) and parsing it at leisure. messing about with scanf is a pain. |
All times are GMT -5. The time now is 06:22 AM. |