Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* File:God.c *
- * Credits:w2ch Anon 22-07-2014 *
- * Description:Creates file of every position posible *
- * WARNING:Run this program only on a supper computer *
- * if you don't want your PC to crash. *
- * NOTE:This code is a mess. */
- #include <stdio.h>
- #include <stdlib.h>
- typedef char bool;
- #define TRUE 1
- #define FALSE 0
- #define The_answer_to_life_and_the_universe_and_everything 42
- // ====================================================================
- // Forward declaration.
- typedef struct DynamicArray_s DynamicArray;
- // Function pointers.
- typedef void(*fpDynamicArray)(DynamicArray *);
- typedef bool(*fpChangeArraySize)(DynamicArray *);
- typedef void(*fpFreeArrayMemory)(DynamicArray *);
- struct DynamicArray_s
- {
- struct DynamicArray_s *this; // this pointer.
- fpDynamicArray DynamicArray; // Constructor.
- fpFreeArrayMemory DynamicArrayFree; // Destructor.
- fpChangeArraySize ChangeArraySize; // Resize array.
- char *m_FileTempData; // The "raw" data of the array.
- int m_nArraySize; // Counter that holds the array size.
- char m_bIncreasArray; // If TRUE ChangeArraySize will increase with 1 byte else nothing happens.
- };
- // Functions
- bool ChangeArraySize(DynamicArray *this) // return FALSE if error.
- {
- if (this->m_bIncreasArray == FALSE) return TRUE;
- char *TempReturnValue = NULL;
- ++this->m_nArraySize;
- TempReturnValue = (char*)realloc(this->m_FileTempData, this->m_nArraySize + 1); // +1 because '\0'.
- if (TempReturnValue == NULL)
- {
- // could not realloc, but orig still valid. We want more memory, so error.
- return FALSE;
- }
- this->m_FileTempData = TempReturnValue;
- // Set the new allocated byte to 0.
- this->m_FileTempData[this->m_nArraySize] = '\0'; // This line "may" only need once and if taken away, optimize the program?
- this->m_FileTempData[this->m_nArraySize - 1] = '\0';
- this->m_bIncreasArray = FALSE;
- return TRUE;
- }
- void DynamicArrayFree(DynamicArray *this)
- {
- if (this->m_FileTempData != NULL) free(this->m_FileTempData);
- }
- void fDynamicArray(DynamicArray *this)
- {
- this->DynamicArrayFree = DynamicArrayFree;
- this->ChangeArraySize = ChangeArraySize;
- this->m_FileTempData = NULL;
- this->m_nArraySize = 0;
- this->m_bIncreasArray = TRUE;
- }
- int main(void)
- {
- DynamicArray FileTempBuffer = { &FileTempBuffer, fDynamicArray };
- FileTempBuffer.DynamicArray(FileTempBuffer.this);
- bool bNoError = TRUE;
- FILE *NewFile = NULL;
- bool bOverflow;
- int i;
- while (The_answer_to_life_and_the_universe_and_everything) //bNoError // Program will never exit on error if not bNoError in while loop.
- {
- if (bNoError = (FileTempBuffer.ChangeArraySize(FileTempBuffer.this)))
- {
- // Add +1 to the buffer.
- for (i = 0, bOverflow = TRUE; bOverflow && i < FileTempBuffer.m_nArraySize; ++i)
- if (bOverflow)
- {
- if ((unsigned char)FileTempBuffer.m_FileTempData[i] == 0xFF)
- FileTempBuffer.m_FileTempData[i] = 0;
- else
- {
- ++FileTempBuffer.m_FileTempData[i];
- bOverflow = FALSE;
- }
- }
- // Create the new file.
- NewFile = fopen(FileTempBuffer.m_FileTempData, "wb"); // Create a new emty binary file, even if the file exist.
- if (NewFile != NULL)
- {
- // Write the new file with information.
- for (i = 0;
- i < FileTempBuffer.m_nArraySize &&
- FileTempBuffer.m_FileTempData[i] != '\0' &&
- fputc(FileTempBuffer.m_FileTempData[i], NewFile) != EOF; ++i);
- // Clean up.
- if (fclose(NewFile) == EOF) bNoError = FALSE;
- }
- else bNoError = FALSE;
- if ((unsigned char)FileTempBuffer.m_FileTempData[FileTempBuffer.m_nArraySize - 1] == 0xFF) FileTempBuffer.m_bIncreasArray = TRUE;
- }
- }
- // Clean up.
- FileTempBuffer.DynamicArrayFree(FileTempBuffer.this);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement