字符转换为数字,以|分割
来源:程序员人生 发布时间:2015-03-25 11:42:50 阅读次数:2245次
#include <stdio.h>
#include <stdlib.h>
#define INT_MAX ((1<<31)⑴)
#define INT_MIN (1<<31)
#define isRight(x) (x==' ' || x=='+' || x=='-' || (x>='0'&&x<='9'))
int getNum(char* s, int begin, int end)
{
int flag = 1;
int num = 0;
while (begin<=end && s[begin] == ' ')
begin++;
if (s[begin] == '-')
{
flag = ⑴;
begin++;
}
if (s[begin] == '+')
begin++;
while (begin<=end)
{
if (s[begin]<'0' || s[end]>'9')
{
return 0;
}
if (num>INT_MAX/10 || (INT_MAX==INT_MAX/10 && (s[begin]-'0')>INT_MAX%10))
return (flag==⑴) ? INT_MIN : INT_MAX;
num = num*10+s[begin]-'0';
begin++;
}
return num*flag;
}
/*以|分隔符的数值转换 1面*/
void strToNum(char* s)
{
int a[20];
int i = 0;
int begin;
int end;
int count = 0;
if (s == NULL)
return;
while (s[i]!='