This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Davidthefat Code

By: a guest on Feb 17th, 2013  |  syntax: C  |  size: 2.86 KB  |  views: 194  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     void bitprint(int n)
  2.     {
  3.             for(int i = sizeof(n)*8-1; i >= 0; i --)//C99 standard for loop and comment.
  4.                     printf("%d", (n&(1<<i))>>i);
  5.     }
  6.  
  7. //It's exactly not a one liner, but this prints out the integer in binary form. The parameter can be changed //to a long if you want.
  8.  
  9.     int gcd(int p, int q)
  10.     {
  11.             for(int i = p < q?p:q; i > 0; i --)
  12.                     if(!(p%i) && !(q%i))
  13.                             return i;
  14.             return -1;
  15.     }
  16.  
  17. //This is not a one liner either, but I like it. It returns the greatest common denominator.
  18.  
  19.     /**
  20.      * @description Finds the character in the string
  21.      * @param string to find in
  22.      * @param character to find
  23.      * @return the pointer to the character in string
  24.      */
  25.     char *find_chr(char *input, char find)
  26.     {
  27.             while(*input != find&&*input++)
  28.                     ;
  29.             return input;
  30.     }
  31.  
  32.     /**
  33.      * @description This splits the string at the inputted character
  34.      * @param original string
  35.      * @param pointer to lower half of the string
  36.      * @param pointer to other half of the string
  37.      * @param character to find and split at
  38.      * @return void
  39.      */
  40.    
  41.     void split(char *orig, char **p, char **s, char c)
  42.     {
  43.             char *temp = find_chr(orig, c);
  44.             char *pop = (char*)malloc(sizeof(char) * (temp - orig));
  45.             *p = pop;
  46.             while(orig != temp)
  47.                     *pop++ = *orig++;
  48.             *s = ++temp;
  49.     }
  50.    
  51.  
  52.  
  53.     /**
  54.      * @description This shifts every character over indicated number of times
  55.      * @param input string to be manipulated
  56.      * @param number of steps to shift over
  57.      * @return void
  58.      */
  59.     void Caesar(char **input, int shift)
  60.     {
  61.             char *temp = (char*)malloc(sizeof(char)*strlen(*input));
  62.             for(int i = 0; i < strlen(*input); i ++){
  63.                     if(isalpha(*(*input+i)))
  64.                             *(temp+i) = (*(*input+i)+shift>122?(96+(shift-(122-tolower(*(*input+i))))):tolower(*(*input+i))+shift);
  65.                     else
  66.                             *(temp+i) = ' ';
  67.             }
  68.             *input = temp;
  69.     }
  70.  
  71.    
  72.     /**
  73.      * @description This reverses the Caesar algorithm
  74.      * @param input string to be manipulated
  75.      * @param number of steps to shift over
  76.      * @return void
  77.      */
  78.     void deCaesar(char **input, int shift)
  79.     {
  80.             char *temp = (char*)malloc(sizeof(char)*strlen(*input));
  81.             for(int i = 0; i < strlen(*input); i ++){
  82.                     if(isalpha(*(*input+i)))
  83.                             *(temp+i) = (*(*input+i)-shift<97?(123-(shift-(tolower(*(*input+i))-97))):tolower(*(*input+i))-shift);
  84.                     else
  85.                             *(temp+i) = ' ';
  86.             }
  87.             *input = temp;
  88.     }
clone this paste RAW Paste Data