#include <stdio.h> #include <windows.h> #include <math.h> /*字符串到整型的转换*/ int swith(char p[],size_t sz) { int i = 0; int sum = 0; for (i; i < sz; i++){ //sum += (p[i]-'0') * pow(10, sz - i - 1); sum = sum * 10 + p[i] - '0'; } printf("%d\n", sum); return 0; } int main() { char p[] = "12345"; int sz = strlen(p); swith (p, sz); system("pause"); return 0; }
实现字符串到整数的转换,例如输入字符串12345,则输出数字12345。
猜你喜欢
转载自blog.csdn.net/qq_39026129/article/details/80544529
今日推荐
周排行