Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.61 KB | None | 0 0
  1.     /* File:God.c                                         *
  2.      * Credits:w2ch Anon 22-07-2014                       *
  3.      * Description:Creates file of every position posible *
  4.      * WARNING:Run this program only on a supper computer *
  5.      * if you don't want your PC to crash.                *
  6.      * NOTE:This code is a mess.                          */
  7.      
  8.      
  9.     #include <stdio.h>
  10.     #include <stdlib.h>
  11.      
  12.      
  13.     typedef char bool;
  14.     #define TRUE 1
  15.     #define FALSE 0
  16.      
  17.     #define The_answer_to_life_and_the_universe_and_everything 42
  18.      
  19.      
  20.     // ====================================================================
  21.      
  22.      
  23.     // Forward declaration.
  24.     typedef struct DynamicArray_s DynamicArray;
  25.      
  26.      
  27.     // Function pointers.
  28.     typedef void(*fpDynamicArray)(DynamicArray *);
  29.     typedef bool(*fpChangeArraySize)(DynamicArray *);
  30.     typedef void(*fpFreeArrayMemory)(DynamicArray *);
  31.      
  32.      
  33.     struct DynamicArray_s
  34.     {
  35.             struct DynamicArray_s   *this;                          // this pointer.
  36.             fpDynamicArray                  DynamicArray;           // Constructor.
  37.             fpFreeArrayMemory               DynamicArrayFree;       // Destructor.
  38.      
  39.             fpChangeArraySize               ChangeArraySize;        // Resize array.
  40.             char                                    *m_FileTempData;        // The "raw" data of the array.
  41.             int                                             m_nArraySize;           // Counter that holds the array size.
  42.             char                                    m_bIncreasArray;        // If TRUE ChangeArraySize will increase with 1 byte else nothing happens.
  43.     };
  44.      
  45.      
  46.     // Functions
  47.     bool ChangeArraySize(DynamicArray *this) // return FALSE if error.
  48.     {
  49.             if (this->m_bIncreasArray == FALSE) return TRUE;
  50.      
  51.             char *TempReturnValue = NULL;
  52.      
  53.             ++this->m_nArraySize;
  54.             TempReturnValue = (char*)realloc(this->m_FileTempData, this->m_nArraySize + 1); // +1 because '\0'.
  55.             if (TempReturnValue == NULL)
  56.             {
  57.                     // could not realloc, but orig still valid. We want more memory, so error.
  58.                     return FALSE;
  59.             }
  60.      
  61.             this->m_FileTempData = TempReturnValue;
  62.      
  63.             // Set the new allocated byte to 0.    
  64.             this->m_FileTempData[this->m_nArraySize] = '\0'; // This line "may" only need once and if taken away, optimize the program?
  65.             this->m_FileTempData[this->m_nArraySize - 1] = '\0';
  66.            
  67.             this->m_bIncreasArray = FALSE;
  68.             return TRUE;
  69.     }
  70.     void DynamicArrayFree(DynamicArray *this)
  71.     {
  72.             if (this->m_FileTempData != NULL) free(this->m_FileTempData);
  73.     }
  74.     void fDynamicArray(DynamicArray *this)
  75.     {
  76.             this->DynamicArrayFree = DynamicArrayFree;
  77.             this->ChangeArraySize = ChangeArraySize;
  78.             this->m_FileTempData = NULL;
  79.             this->m_nArraySize = 0;
  80.             this->m_bIncreasArray = TRUE;
  81.     }
  82.      
  83.      
  84.     int main(void)
  85.     {
  86.             DynamicArray FileTempBuffer = { &FileTempBuffer, fDynamicArray };
  87.             FileTempBuffer.DynamicArray(FileTempBuffer.this);
  88.            
  89.             bool bNoError = TRUE;
  90.             FILE *NewFile = NULL;
  91.             bool bOverflow;
  92.             int i;
  93.      
  94.             while (The_answer_to_life_and_the_universe_and_everything) //bNoError // Program will never exit on error if not bNoError in while loop.
  95.             {
  96.                     if (bNoError = (FileTempBuffer.ChangeArraySize(FileTempBuffer.this)))
  97.                     {
  98.                             // Add +1 to the buffer.
  99.                             for (i = 0, bOverflow = TRUE; bOverflow && i < FileTempBuffer.m_nArraySize; ++i)
  100.                             if (bOverflow)
  101.                             {
  102.                                     if ((unsigned char)FileTempBuffer.m_FileTempData[i] == 0xFF)
  103.                                             FileTempBuffer.m_FileTempData[i] = 0;
  104.                                     else
  105.                                     {
  106.                                             ++FileTempBuffer.m_FileTempData[i];
  107.                                             bOverflow = FALSE;
  108.                                     }
  109.                             }
  110.      
  111.                             // Create the new file.
  112.                             NewFile = fopen(FileTempBuffer.m_FileTempData, "wb"); // Create a new emty binary file, even if the file exist.
  113.                             if (NewFile != NULL)
  114.                             {
  115.                                     // Write the new file with information.
  116.                                     for (i = 0;
  117.                                             i < FileTempBuffer.m_nArraySize &&
  118.                                             FileTempBuffer.m_FileTempData[i] != '\0' &&
  119.                                             fputc(FileTempBuffer.m_FileTempData[i], NewFile) != EOF; ++i);
  120.      
  121.                                     // Clean up.
  122.                                     if (fclose(NewFile) == EOF) bNoError = FALSE;
  123.                             }
  124.                             else bNoError = FALSE;
  125.      
  126.                             if ((unsigned char)FileTempBuffer.m_FileTempData[FileTempBuffer.m_nArraySize - 1] == 0xFF) FileTempBuffer.m_bIncreasArray = TRUE;
  127.                     }
  128.             }
  129.            
  130.             // Clean up.
  131.             FileTempBuffer.DynamicArrayFree(FileTempBuffer.this);
  132.             return 0;
  133.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement