Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // printf
- #include <string.h> // strlen
- #include <math.h> // pow
- int intFromAscii(char ascii) {
- switch(ascii) {
- case '1': return 1;
- case '2': return 2;
- case '3': return 3;
- case '4': return 4;
- case '5': return 5;
- case '6': return 6;
- case '7': return 7;
- case '8': return 8;
- case '9': return 9;
- default: return 0;
- }
- }
- int main(int argc, const char** args) {
- if(argc <= 1) return 0;
- const char* input = args[1];
- int total = 0;
- int len = strlen(input);
- for(int i = len-1; i+1 > 0; i--) {
- int power = len - i - 1;
- total += pow(10, power) * intFromAscii(input[i]);
- }
- if(input[0] == '-') total = total * -1;
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement