-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharUtils.cpp
More file actions
26 lines (21 loc) · 833 Bytes
/
Copy pathcharUtils.cpp
File metadata and controls
26 lines (21 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include "charUtils.h"
using namespace std;
int stringToNumber(char chars[]) {
int result = 0;
if (chars == NULL || chars[0] == '\n' || chars[0] == '-') {
cout << "input invalid, Support only number";
return 0;
}
int digit = chars[0] - '0';
int i = 1;
while (chars[i] != '\0') {
digit = (chars[i] - '0') + (digit * 10);
cout << "digit " << digit << '\n';
i++;
if(i > 9) {
throw invalid_argument("input argument length big than 9");
}
}
return digit;
}