home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / challenge / 13.12 / Challenge.sit.hqx / Challenge / bitnumLister.c next >
C/C++ Source or Header  |  1997-10-23  |  1KB  |  53 lines

  1.  
  2. void main(void)
  3. {
  4.     StandardFileReply    reply;
  5.     short    refnum;
  6.     long     i;
  7.     OSType    mySeparator = ',\r  ';
  8.     OSType    mySpace = '    ';
  9.     long    lineCt = 0;
  10.     
  11.     InitGraf(&qd.thePort);
  12.     InitFonts();
  13.     InitWindows();
  14.     InitMenus();
  15.     TEInit();
  16.     InitDialogs(nil);
  17.     InitCursor();
  18.     
  19.     StandardPutFile("\p", "\pbitnum", &reply);
  20.     if (!reply.sfGood || reply.sfReplacing)
  21.         ExitToShell();
  22.     if (FSpCreate(&reply.sfFile, 'ttxt', 'TEXT', reply.sfScript))
  23.         ExitToShell();
  24.     FSpOpenDF(&reply.sfFile, fsRdWrPerm, &refnum);
  25.     
  26.     for ( i= 0; i <= (256 * 256 - 1); i++)
  27.     {
  28.         long    bitShift, shifted;
  29.         long    bitsCt = 0;
  30.         long    stringSize;
  31.         Str255    myString;
  32.         
  33.         for (bitShift = 0; bitShift < 16; bitShift++)
  34.             if ((i >> bitShift) & 0x01)
  35.                 bitsCt++;
  36.         
  37.         NumToString(bitsCt, myString);
  38.         stringSize = myString[0];
  39.         if (stringSize == 1)
  40.             FSWrite(refnum, &stringSize, &mySpace);
  41.         FSWrite(refnum, &stringSize, &myString[1]);
  42.         
  43.         if (++lineCt == 16)
  44.         {
  45.             stringSize = 2;
  46.             lineCt = 0;
  47.         } else
  48.             stringSize = 1;
  49.         FSWrite(refnum, &stringSize, &mySeparator);
  50.     }
  51.     
  52.     FSClose(refnum);
  53. }