开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜