ANSI C: Pass variables from (s)scanf to function call
My question is whether or not it is possible to directly pass the parsed stuff from (s)scanf to a function call. In other words whether I have to initialise the variables which I want to pass to开发者_StackOverflow社区 the function (and read via scanf) or not.
sscanf
returns the number of successful conversions. It does not return the converted values.
So, you wouldn't be passing in the newly converted data when passing the return value of sscanf
directly into another function (if that is what you are asking).
sscanf
, as others said, won't return the values, so there's no "directly" passing them. You can, however, wrap it with something like this:
struct mydata* parse(char* string) {
struct mydata* ret = (struct mydata*) malloc(sizeof(struct mydata));
sscanf(string, /* load the structure with the data */);
return ret;
}
You can call whatever functions you need around that.
精彩评论