In case of only <stdio.h> and <string> header files, extract userid=123456 from below
HTTPS://WWW.CNBLOGS.COM/YSJD userid=123456 passwd=513920
The code is as follows:
1#include <stdio.h>2#include <string.h>3 4 intMyatoi (Charstr[])5 {6 intlen=strlen (str);7 Char*p=str+len-1;8 intsum=0, i=0, num;9 while(p>=str)Ten { Onenum=*p- -; A for(intj=0; j<i;j++) - { -num*=Ten; the } -i++; -sum+=num; -p--; + } - returnsum; + } A at intGetUserId (Char*p,int*N) - { - Char*q=strstr (P,"userid="); - if(q==NULL) - return 0; -q+=7; in Charstr[ -]; - intI=0; to while(*q>='0'&& *q<='9') + { -str[i]=*Q; thei++; *q++; $ }Panax Notoginsengstr[i]=' /'; -*n=myatoi (str); the return 1; + } A intMain () the { + Charstr[]="HTTPS://WWW.CNBLOGS.COM/YSJD userid=123456 passwd=513920"; - intN; $ intRet=getuserid (str,&n); $ if(ret==0) - { -printf"Not found\n");49 } - ElseWuyi { theprintf"userid=%d\n", n); - } Wu}
C Language Extraction String