Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Binary to hex converter...

Name: Needs more Boobs 2008-08-12 21:04

So, /prog/, I created a binary to hex converter (but not the other way around), whose output looks reminds me of broken Japanese. What does /prog/ think?


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (void)
{
   char * hi [16] = { "b", "d", "f", "g", "h", "j", "k", "m", "n",
      "p", "r", "s", "t", "w", "y", "z" };
   char * lo [16] = { "a", "e", "i", "o", "u", "aa", "ee", "ii", "oo",
      "uu", "ai", "ei", "oe", "oi", "ue", "ui" };
   int in, bc, nw, wc;

   srand(time(NULL));

   bc = 0;
   wc = 0;
   nw = (rand() % 5) + 1;

   in = getchar();
   while (in != EOF)
   {
      printf("%s%s", hi[in >> 4], lo[in & 15]);
      in = getchar();
      bc++;
      if (bc == nw)
      {
         wc++;
         if (wc == 5)
         {
            putchar('\n');
            wc = 0;
         }
         else putchar(' ');
         nw = (rand() % 5) + 1;
         bc = 0;
      }
   }

   return 0;
}


Now you can spam CP onto boards and no one will know.

Name: Anonymous 2008-08-12 21:46

first of all your indentation is disgusting
secondly your "in = getchar();" both just before and inside the loop suggests that you should simplify it.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List