Advertisement
robonx12

Fucking epic number machine

May 27th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5.  
  6.  
  7. #define MAX 15
  8.  
  9. bool Transfer(int, char *, int);
  10.  
  11. int main(int argc, char **argv) {
  12.     char string[MAX];
  13.     memset(string, '\0', sizeof(char) * MAX);
  14.     Transfer(atoi(argv[1]), string, atoi(argv[2]));
  15.     int counter = strlen(string);
  16.     char swapstring[counter];
  17.     for (int i = 0, j = counter - 1; i < counter; j--, i++) {
  18.         swapstring[i] = string[j];
  19.     }
  20.     printf("%s", swapstring);
  21.  
  22. }
  23.  
  24. bool Transfer(int number, char *string, int sys) {
  25.     int rest;
  26.     int counter = 0;
  27.     while(1) {
  28.         if ((rest = number % sys) >= 10) {
  29.             string[counter] = rest + 55;
  30.         } else {
  31.             string[counter] = rest + 48;
  32.         }
  33.         if ((number = number / sys) == 0) {
  34.             return true;
  35.         }
  36.         if ((number != 0 && counter >= MAX - 1)) {
  37.             return false;
  38.         }
  39.         counter++;
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement