1

I'm trying to write a script to except data from GET request using sscanf. I seem to be having a problem with parsing it with sscanf and passing it on to a variable. I think that the issue is something to do with my char type, but may also have to do with my Regex string because the error gives the group as "%[a-z,A-Z" and not "%[a-z,A-Z]" like I'd expect it to. You can see the full source code at http://cs.mcgill.ca/~phwang3/cgi-bin/searchRecord.c, but I've highlighted the main stuff here.

I seem to be getting an error

 warning: format ‘%[a-z,A-Z’ expects argument of type ‘char *’, but argument 3 has type ‘char * (*)[20]’ [-Wformat]

at this line

if(sscanf(data,"firstName=%[a-z,A-Z]&lastName=%[a-z,A-Z]",&firstName, &lastName)!=2) {

the variables in question are declared before the above line as

char firstName[20] = {0};
char lastName[20] = {0};

also relevant, I suppose, is that the query is stored in the variable "data", and also declared before the poblematic string.

char* data;
data = getenv("QUERY_STRING");
4

1 回答 1

3
if(sscanf(data,"firstName=%[a-z,A-Z]&lastName=%[a-z,A-Z]",
    &firstName, &lastName)!=2) {

You have to pass firstName and lastName and not &firstName and &lastName.

于 2013-03-30T17:52:30.847 回答