简单问题
若输入字符串"-1234",则函数把它转换为整数值 -1234如何做
#include <stdio.h> #include <string.h> long fun ( char *p) { int i=0,x=0; while(p[i] != '\0') { if (p[0] == '-') { for(i = 1; p[i] != '\0';) { x=(p[i] - '0') + 10 * x; i++; } x *= -1; } else { x = 10 * x + (p[i] - '0'); i++; } } return x; } main() /* 主函数 */ { char s[6]; long n; printf("Enter a string:\n") ; gets(s); n = fun(s); printf("%ld\n",n); //NONO ( ); }