开发者

sscanf skip over white-space in beginning

开发者 https://www.devze.com 2023-01-20 18:16 出处:网络
I want to read in a string开发者_运维百科 and parse it with sscanf. Although i don\'t want to read in any spaces in the beginning.

I want to read in a string开发者_运维百科 and parse it with sscanf. Although i don't want to read in any spaces in the beginning.

Sample string.

@a Bear Tiger

sscanf(strLine, "@%1s %64s %64s", dir, name1, name2);

I have that.

Problem is if the line goes in as say

        @a Bear Tiger

Should be:

@a Bear Tiger

that it will want to read in the spaces up to the @ character. How can i skip over white-space and read from the @ character.

Thanks.


sscanf(strLine, " @%1s %64s %64s", dir, name1, name2);

This is necessary because scanf only skips whitespace for (most) conversion specifications. But @ is an "ordinary character", not a conversion specification, so there is no skip. However, adding whitespace to the format string forces input whitespace to be skipped.

0

精彩评论

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