integer extraction from string

前端 未结 5 972
天命终不由人
天命终不由人 2021-01-26 18:37

I have an input argument string const char* s I know that it starts the sequence of chars which are integers representation ,this sequence could be of any length ,

5条回答
  •  一个人的身影
    2021-01-26 19:01

    One way would be to use sscanf:

    char *str = "23meeting";
    unsigned x;
    sscanf(str, "%u", &x);
    printf("%u\n", x);
    

    For additional error-checking, though, you'll have to do some additional manual checks.

提交回复
热议问题