字符串转unsigned int函数-C语言实现

unsigned string_to_unsigned(char *s)
{
	unsigned result = 0;
	for (int i = strlen(s) - 1; i >= 0; --i){
		unsigned temp = 0;
		int k = strlen(s) - i - 1;
		if (isdigit(s[i])){
			temp = s[i] - '0';
			while (k--){
				temp *= 10;
			}
			result += temp;
		}
		else{
			break;
		}
	}
	return result;
}

你可能感兴趣的:(字符串转unsigned int函数-C语言实现)