📄 strtouint.h
字号:
#ifndef __STRTOUINT_HEADER_INCLUDED__#define __STRTOUINT_HEADER_INCLUDED__/* Error detecting string to unsigned int conversion.* Return values:* <0 - error (such as overflow, or not-a-number)* =0 - the input string was perfect* >0 - the input string had trailing garbage, return* value tells you how many bytes were numbers.*/#include <ctype.h>static inline int strtouint(const char *s, unsigned int *v){ unsigned int d; int p=0; int base=10; if ( s[0]=='0' ) { base=8; s++; p++; } if ( *s && base==8 && *s=='x' ) { base=16; s++; p++; } if ( base <= 10 ) { for(*v=0; (d=(unsigned int)(*s - '0')) < base; p++) { *v=*v*base+d; s++; } }else{ for(*v=0; ; p++) { if ( (d=(unsigned int)(*s - '0'))>=10 && (d=((unsigned int)(tolower(*s) - 'a')+10))>=base ) break; *v=*v*base+d; s++; } } if ( p==0 ) { if ( base==8 ) { *v=0; }else{ *v=0; return -1; } } if ( *s==0 ) return 0; return p;}#ifndef __PLUGIN__#else#endif#endif /* __STRTOUINT_HEADER_INCLUDED__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -