integer extraction from string

前端 未结 5 1010
天命终不由人
天命终不由人 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条回答
  •  Happy的楠姐
    2021-01-26 19:00

    You can iterate through the string and can give the condition to get numbers

    num=0;
    for(i=0;str[i]!='\0';i++) {
    if(str[i]>=48 && str[i]<=57)
     num=num*10+(str[i]-48);
      printf("\n%d",num);
    } 
    

提交回复
热议问题