Advertisement
_fur

_fur | C Isa

Dec 15th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4. #include <string.h>
  5.  
  6. #define MAX_CHAR 0xFFF0
  7.  
  8. int main(void)
  9. {
  10.         const char DELIM = ' ';
  11.  
  12.         int i, j, k = 0;
  13.         int len;
  14.         char buff[9] = "";
  15.         char temp[2] = "";
  16.         char *in = malloc(MAX_CHAR);
  17.         char *text = malloc(MAX_CHAR);
  18.  
  19.         if (in == NULL | text == NULL)
  20.                 return ENOMEM;
  21.  
  22.         printf("Input biner : ");
  23.         fgets(in, MAX_CHAR - 3, stdin);
  24.  
  25.         len = strlen(in);
  26.         for (i = len - 1; i > -1; i--)
  27.                 if (in[i] != DELIM && (in[i] == '1' | in[i] == '0')) {
  28.                         buff[k++] = in[i];
  29.                 } else if (in[i] == DELIM) {
  30.                         memset(temp, 0, 2);
  31.  
  32.                         for(j = 0; j < 8; j++)
  33.                                 temp[0] += (buff[j] - '0') << j;
  34.  
  35.                         if (temp[0])
  36.                                 strcat(text, temp);
  37.  
  38.                         memset(buff, 0, 9);
  39.                         k = 0;
  40.                 }
  41.  
  42.         len = strlen(text);
  43.         for (i = 0; i < len / 2; i++) {
  44.                 char t = text[i];
  45.                 text[i] = text[len - i - 1];
  46.                 text[len - i - 1] = t;
  47.         }
  48.  
  49.         printf("%s\n", text);
  50.  
  51.         free(in);
  52.         free(text);
  53.  
  54.         return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement