sscanf remove right bracket C

时间:2016-07-11 22:46:48

标签: scanf

I am trying to extract a string within paranthesis {abcdefg}

sscanf(line,"{%s}", value);

Example: {abcdefg} after sscanf I get abcdefg}

How can I remove the right bracket? I need to get abcdefg

1 个答案:

答案 0 :(得分:0)

With POSIX (s)scanf, you can use %[^}] to extract everything up to a }:

#include <stdio.h>
int main(){
    const char* line = "{abcdefg}";
    char extract[100];

    sscanf(line, "{%[^}]",  extract);
    puts(extract); //prints abcdefg

    return 0;
}