haseeb_heaven

GameGenieMasterListGenerator.c

Feb 22nd, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 20.95 KB | None | 0 0
  1. //GameGenieMasterListGenetator Generates List of All possible GameGenie Codes.
  2. //Written by Haseeb Mir (haseebmir.hm@gmail.com)
  3. //Dated 23/02/2017.
  4.  
  5. //GameGenie Refrence by The Mighty Mike Master : http://tuxnes.sourceforge.net/gamegenie.html
  6. //Thanks to Mighty Mike for his amazing refrence.
  7.  
  8. //Thanks to Jsdemonsim for his efficent Alphabet_generation Algorithm .
  9. //code could be found here https://github.com/Jsdemonsim/Stackoverflow/blob/master/alphabet/alphabet.c
  10.  
  11. //Including Standard Libraries.
  12. #include <stdio.h> //For Standatd I/O Operations.
  13. #include <stdlib.h> //For Exit() Function.
  14. #include <string.h> //For strrev() and strlen() functions.
  15. #include <stdbool.h> //For _Bool Boolean.
  16. #include <ctype.h> //For isUpper(). isLower()
  17. #include <time.h> //For Clock .
  18. #include <math.h> //For pow().
  19.  
  20. //Defining Constants in form of Macros.
  21. #define NO_OF_CHARS 256 //For Ducplicate Inputs.
  22. #define GAME_GENIE_LEN 8 //MAX Length of GameGenie Code, Don't edit this.
  23. #define GAME_GENIE_TABLE_LEN 16 //MAX GameGenie Table Length.
  24.  
  25. //Generates All Possible Combinations using this input.
  26. char GameGenieInput[] = "ANXG"; //Change here for different input.
  27.  
  28. //Default input is set to 5-Character combination but input could be between 2 to 16 Chars combination long taken from GameGenieTable.
  29.  
  30. //"APZLGITYEOXUKSVN" this is example of 16-Chars string for MAX Input.
  31.  
  32. /*
  33. Output of 16-char MAX input .
  34.  
  35. File Created : GameGenieMasterList.txt
  36. 16777216 GameGenieCodes Written in File
  37. Time Taken = 126.064000 seconds
  38. File Size : 895 MB (MegaBytes)
  39. */
  40.  
  41. //GameGenie Code Table.
  42. const char GameGenieTable[GAME_GENIE_TABLE_LEN] =
  43. {
  44.     'A','P','Z','L','G','I','T','Y',
  45.     'E','O','X','U','K','S','V','N',
  46. }; //Master GameGenie Table.
  47.  
  48. short n0,n1,n2,n3,n4,n5,n6,n7; //Contains HEX of GameGenieCode, n0 = 1st Char ... n7 = 8th GameGenie Character.  
  49. static _Bool is_8_Char_GameGenie = false; //Checking for 8-Character GameGenie Code.
  50. int _count_6Char = 0,_count_8Char = 0,_failedCount = 0; //Counters for 6 or 8 Char GameGenieCode and counter for failedCode.
  51.  
  52. //Jsdemonsim's written Alphabet Generation Algorithm .
  53. static void generate_combinations(int);
  54.  
  55. //GameGenieCode subroutines.
  56. void generateGameGenieList(char*,int);
  57. int checkGameGenieCode(char *);
  58. int getGameGenieLen();
  59.  
  60. //GameGenie value & Address. Routines.
  61. int decodeGameGenieCode(char *);
  62. int decodeGameGenieAddress();
  63. int decodeGameGenieValue();
  64. int decodeGameGenieCompare();
  65.  
  66. //For Checking duplicate  & Wrong Inputs.
  67. int check_input(char *);
  68. _Bool check_duplicates(char *);
  69. char *remove_duplicates(char *);
  70.  
  71. //Converting Input to UpperCase if needed.
  72. _Bool isInputLower(char *str);
  73. void toUpperCase(char *);
  74.  
  75. //Printing Title to Files.
  76. void printFileTitle();
  77.  
  78. //Global variables.
  79. long long TotalCodes = 0; //Count the Total number of Codes Generated.
  80. FILE *_fp_6Char_GG,*_fp_8Char_GG,*_fp_failedCodes; //FilePointer to GameGenieCodes and FailedCodes File.
  81.  
  82. int main()
  83. {
  84.                    
  85.     //Creating Timer to count time elapsed while generating MasterList .
  86.     clock_t start;
  87.     double time_used;
  88.     start = clock();
  89.    
  90.                 //Holds the Total Possbile codes depends on 'N' length of Input.
  91.                 long long totalPossibleCodes = (pow(getGameGenieLen(),6) + pow(getGameGenieLen(),8));
  92.     char *New_Input;//Holds the New_Input after removing duplicates from GameGenieInput.
  93.                                
  94.     //Creating Three Files to Hold 6 or 8 GameGenie Codes and failedCodes for any failed Code not generated .
  95.     char GameGenie_6Char[] = "GameGenie_6_CharsList.txt"; //For 6-Character GameGenie.
  96.                 char GameGenie_8Char[] = "GameGenie_8_CharsList.txt"; //For 8-Character GameGenie.
  97.                 char GameGenie_failedCodes[] = "GameGenie_failedCodesList.txt"; //For Failed Codes or Junk Data.
  98.  
  99.                 //Always Open File in Write Mode.
  100.     _fp_6Char_GG = fopen(GameGenie_6Char, "w");
  101.     _fp_8Char_GG = fopen(GameGenie_8Char, "w");
  102.     _fp_failedCodes = fopen(GameGenie_failedCodes, "w");
  103.    
  104.     //Checking for failed Memory allocation.
  105.     if (_fp_6Char_GG == NULL || _fp_8Char_GG == NULL || _fp_failedCodes == NULL)
  106.     {
  107.         perror("Error : "); //Perror Automatically detects the type of error occured and prints that error.
  108.         exit(1); //Exit with Error.
  109.     }
  110.                                
  111.     //Convert Input to UpperCase if it isn't already.
  112.         if(isInputLower(GameGenieInput))
  113.                 toUpperCase(GameGenieInput);
  114.  
  115.     //Checking  for Wrong Input, Length In-Range and for Duplicates.
  116.     if(check_input(GameGenieInput))
  117.     {
  118.         if(getGameGenieLen() > 1 && getGameGenieLen() <= GAME_GENIE_TABLE_LEN)
  119.         {
  120.  
  121.             //Check for Duplicate Inputs before generating all combinations.
  122.             if(check_duplicates(GameGenieInput))
  123.             {
  124.  
  125.                 //Copies the new input.
  126.                 New_Input = remove_duplicates(GameGenieInput);
  127.  
  128.                 //Checking special Condition
  129.                 if(strlen(New_Input) == 1)
  130.                 {
  131.                     printf("After removing duplicates\nGameGenieInput Length was not Sufficent to generate Combinations.\n");
  132.                     exit(EXIT_FAILURE);
  133.                 }
  134.  
  135.                 else
  136.                     printf("Duplicates were removed from Input.\nNew Input is : %s\n",New_Input);
  137.             }
  138.  
  139.                                                     //Prints Waiting Message for Large Inputs.
  140.                                                     if(getGameGenieLen() > 5)
  141.                                                      printf("Generating GameGenie Codes Please Wait...");
  142.            
  143.             //Prints Title to all Files before Genrating Codes.
  144.             printFileTitle();
  145.            
  146.                                                 //Generates All the Possbile Combinations of using GameGenieTable.
  147.             generate_combinations(GAME_GENIE_LEN);
  148.         }
  149.  
  150.         else
  151.         {
  152.             printf("GameGenieInput Length out of Range.\n");
  153.             exit(EXIT_FAILURE);
  154.         }
  155.  
  156.     }
  157.     else
  158.     {
  159.         printf("Wrong GameGenieInput entered.\n");
  160.         exit(EXIT_FAILURE);
  161.     }
  162.  
  163.                
  164.     time_used = ((double) (clock() - start)) / CLOCKS_PER_SEC;
  165.     _failedCount =  totalPossibleCodes - TotalCodes;
  166.     printf("\nFiles Created Successfully :\n\n%s\n%s\n%s\n\n",GameGenie_6Char,GameGenie_8Char,GameGenie_failedCodes);
  167.                
  168.                 printf("Codes Summary :\n\n");
  169.                 printf("6-Character GameGenieCodes Generated : %d\n",_count_6Char);
  170.                 printf("8-Character GameGenieCodes Generated : %d\n",_count_8Char);
  171.                 printf("Total GameGenieCodes Generated : %d\n\n",TotalCodes);          
  172.                    
  173.                 printf("GameGenieCodes Failed to Generate : %d\n",_failedCount);
  174.                 printf("Time Taken = %f seconds\n\n",time_used);
  175.  
  176.                 //Print Title at the End also.
  177.                 printFileTitle();
  178.                
  179.     //Close the File handles.
  180.     fclose(_fp_6Char_GG);
  181.                 fclose(_fp_8Char_GG);
  182.                 fclose(_fp_failedCodes);
  183.                
  184.     return EXIT_SUCCESS;
  185. }
  186.  
  187.  
  188. //Jsdemonsim's written Alphabet Generation Algorithm .
  189.  
  190. //Generates All possible combinations of given input.
  191. static void generate_combinations(int maxlen)
  192. {
  193.     int   alphaLen = strlen(GameGenieInput);
  194.     int   len    = 0;
  195.     char  *buffer  = (char*)malloc((maxlen + 1) * alphaLen * alphaLen);
  196.     int  *letters  = (int*)malloc(maxlen * sizeof(int));
  197.  
  198.     if (buffer == NULL || letters == NULL)
  199.     {
  200.         fprintf(stderr, "Not enough memory.\n");
  201.         exit(EXIT_FAILURE);
  202.     }
  203.  
  204.     // This for loop generates all 1 letter patterns, then 2 letters, etc,
  205.     // up to the given maxlen.
  206.     for (len=6; len<=maxlen; len++)
  207.     {
  208.         // The stride is one larger than len because each line has a '\n'.
  209.         int i;
  210.         int stride = len+1;
  211.         int bufLen = stride * alphaLen * alphaLen;
  212.  
  213.         if (len == 1)
  214.         {
  215.             // Special case.  The main algorithm hardcodes the last two
  216.             // letters, so this case needs to be handled separately.
  217.             int j = 0;
  218.             bufLen = (len + 1) * alphaLen;
  219.             for (i=0; i<alphaLen; i++)
  220.             {
  221.                 buffer[j++] = GameGenieInput[i];
  222.                 buffer[j++] = '\n';
  223.             }
  224.  
  225.             //Generates GameGenieCodes with Current Buffer.
  226.             generateGameGenieList(buffer,bufLen);
  227.  
  228.             continue;
  229.         }
  230.  
  231.         // Initialize buffer to contain all first letters.
  232.         memset(buffer, GameGenieInput[0], bufLen);
  233.  
  234.         // Now write all the last 2 letters and newlines, which
  235.         // will after this not change during the main algorithm.
  236.         {
  237.             // Let0 is the 2nd to last letter.  Let1 is the last letter.
  238.             int let0 = 0;
  239.             int let1 = 0;
  240.             for (i=len-2; i<bufLen; i+=stride)
  241.             {
  242.                 buffer[i]   = GameGenieInput[let0];
  243.                 buffer[i+1] = GameGenieInput[let1++];
  244.                 buffer[i+2] = '\n';
  245.                 if (let1 == alphaLen)
  246.                 {
  247.                     let1 = 0;
  248.                     let0++;
  249.                     if (let0 == alphaLen)
  250.                         let0 = 0;
  251.                 }
  252.             }
  253.         }
  254.  
  255.         //Generates GameGenieCodes with Current Buffer.
  256.         generateGameGenieList(buffer,bufLen);
  257.  
  258.         // Special case for length 2, we're already done.
  259.         if (len == 2)
  260.             continue;
  261.  
  262.         // Set all the letters to 0.
  263.         for (i=0; i<len; i++)
  264.             letters[i] = 0;
  265.  
  266.         // Now on each iteration, increment the the third to last letter.
  267.         i = len-3;
  268.         do
  269.         {
  270.             char c;
  271.             int  j;
  272.  
  273.             // Increment this letter.
  274.             letters[i]++;
  275.  
  276.             // Handle wraparound.
  277.             if (letters[i] >= alphaLen)
  278.                 letters[i] = 0;
  279.  
  280.             // Set this letter in the proper places in the buffer.
  281.             c = GameGenieInput[letters[i]];
  282.             for (j=i; j<bufLen; j+=stride)
  283.                 buffer[j] = c;
  284.  
  285.             if (letters[i] != 0)
  286.             {
  287.                 // No wraparound, so we finally finished incrementing.
  288.                 // Write out this set.  Reset i back to third to last letter.
  289.  
  290.                 //Generates GameGenieCodes with Current Buffer.
  291.                 generateGameGenieList(buffer,bufLen);
  292.  
  293.                 i = len - 3;
  294.                 continue;
  295.             }
  296.  
  297.             // The letter wrapped around ("carried").  Set up to increment
  298.             // the next letter on the left.
  299.             i--;
  300.             // If we carried past last letter, we're done with this
  301.             // whole length.
  302.             if (i < 0)
  303.                 break;
  304.         }
  305.         while(1);
  306.     }
  307.  
  308.     // Clean up.
  309.     free(letters);
  310.     free(buffer);
  311. }
  312.  
  313. //Generates GameGenie MasterList.
  314. void generateGameGenieList(char *CodeGenieBuffer,int buffLen)
  315. {
  316.    
  317.     int GG_CodeCount = 0,i = 0;
  318.  
  319.     //Calculating Number of GameGenie Codes present in current CodeGenie Buffer.
  320.     while(CodeGenieBuffer[i])
  321.     {
  322.  
  323.         //If there is '\n' means we have iterated over that GameGenie.
  324.         if(CodeGenieBuffer[i] == '\n')
  325.             GG_CodeCount++; //Count for every GameGenie Code Present.
  326.  
  327.         i++;
  328.     }
  329.    
  330.                 //printf("GG_CodeCount = %d , bufflen = %d , (buffLen by GG_CodeCount) = %d\n",GG_CodeCount,buffLen,(buffLen / GG_CodeCount));
  331.                                                
  332.                 if((buffLen / GG_CodeCount) == 8) //Skips for 7-Character Buffer Generated.
  333.                 return ; //Return Control back.
  334.                
  335.                 else{
  336.                                                                                                    
  337.                 //Contains Total number of Codes in Buffer and their length.
  338.                 int index = 0,BufferIndex = 0,CodeGenieIndex = 0,CodeGenieCount = 0,CodeGenieLen = 0;
  339.                
  340.                 //Contains 6 or 8-character GameGenie Code from large generated code Buffer.
  341.              char GameGenieCode[ (is_8_Char_GameGenie == true) ? (sizeof (char) * 8) : (sizeof (char) * 6)];
  342.                  memset(GameGenieCode,'\0',sizeof(GameGenieCode)); //Setting 0 as initial value.       
  343.                        
  344.                                     //Checking 8-Char GameGenie for Every Buffer.
  345.                                     if((buffLen / GG_CodeCount) == GAME_GENIE_LEN   + 1)
  346.                                         is_8_Char_GameGenie = true;
  347.        
  348.                                            
  349.         //Code Buffer has some -ve Values junk strings at the end. Don't process them.
  350.         while(CodeGenieBuffer[index] > 0)
  351.         {
  352.            
  353.             //Count the Seperate GameGenie Codes from Large Code Chunks.
  354.             if(CodeGenieBuffer[index] == '\n')
  355.             {
  356.                 CodeGenieCount++;
  357.                 index++; //Skip one character if '\n' occurs in copying from code Buffer.
  358.             }
  359.  
  360.             //Reset the CodeGenie Index counter.
  361.             if(CodeGenieIndex >= (is_8_Char_GameGenie ? 8 : 6))
  362.                                                  CodeGenieIndex = 0;
  363.                                                
  364.                                                                                                
  365.             //If we have reached the First/Second and so on GameGenieCode in Buffer then copy that specific code.
  366.             if(CodeGenieCount == BufferIndex)
  367.             {
  368.                 GameGenieCode[CodeGenieIndex] = CodeGenieBuffer[index];
  369.                 CodeGenieLen++;
  370.             }
  371.            
  372.             //Insert Null dont let any junk data to be processed further.
  373.                                                  GameGenieCode[8] = '\0';  
  374.                                                
  375.             //Checking length of CodeGenie.
  376.             if(CodeGenieLen == ((is_8_Char_GameGenie ? 8 : 6) * (BufferIndex+1) ))
  377.             {
  378.                 //After every 6 or 8 chars there is '\n' from which we are keeping track of individual GameGenieCode.
  379.                                                                    
  380.                 if(decodeGameGenieCode(GameGenieCode))
  381.                 {
  382.                                 //If it's 6-Character GameGenie Code.
  383.                                                                                 if(!is_8_Char_GameGenie){
  384.                                                                                 //Writes all the GameGenieCodes to File.
  385.                     fprintf(_fp_6Char_GG,"GameGenieCode = %s\n",GameGenieCode); //Prints current GameGenieCode.
  386.                     fprintf(_fp_6Char_GG, "Address = 0x%x\n",decodeGameGenieAddress()); //Prints Address in Hex.
  387.                     fprintf(_fp_6Char_GG, "value = %x\n",decodeGameGenieValue()); //Prints value in Hex.
  388.                     fprintf(_fp_6Char_GG,"\n");
  389.                                                                                 _count_6Char++;
  390.                                                                                 }
  391.                    
  392.                     //If it's 8-Character GameGenie Code.
  393.                     if(is_8_Char_GameGenie){        
  394.                                                                                  //Writes all the GameGenieCodes to File.
  395.                     fprintf(_fp_8Char_GG,"GameGenieCode = %s\n",GameGenieCode); //Prints current GameGenieCode.
  396.                     fprintf(_fp_8Char_GG, "Address = 0x%x\n",decodeGameGenieAddress()); //Prints Address in Hex.
  397.                     fprintf(_fp_8Char_GG, "value = %x\n",decodeGameGenieValue()); //Prints value in Hex.            
  398.                     fprintf(_fp_8Char_GG, "compare = %x\n",decodeGameGenieCompare()); //Prints Compare Value in Hex.
  399.                     fprintf(_fp_8Char_GG,"\n");
  400.                                                                                 _count_8Char++;
  401.                                                                                 }
  402.                                                                                                                                                                                                                        
  403.                     //Counting for Total Number of Codes Generated.
  404.                     TotalCodes++;
  405.                 }
  406.  
  407.                 //Writing for any Failed GameGenie Code or Any Junk Data.
  408.                 else
  409.                  fprintf(_fp_failedCodes,"%s\n",GameGenieCode);
  410.                     //printf("\n%s is not a valid GameGenie Code\n",GameGenieCode);
  411.                                                        
  412.                 //Incrementing Bufferindex.
  413.                 BufferIndex++;
  414.             }
  415.  
  416.             //Incrementing index and CodeGenieIndex.
  417.             index++;
  418.             CodeGenieIndex++;
  419.         }
  420.            
  421.                 }
  422. }
  423.  
  424. //decode GameGenieCode.
  425. int decodeGameGenieCode(char *GameGenieCode)
  426. {
  427.  
  428.     int i = 0,j = 0,found = 0;
  429.                
  430.     for(i = 0; i < (is_8_Char_GameGenie ? 8 : 6) ; i++)
  431.     {
  432.     for(j = 0; j < GAME_GENIE_TABLE_LEN; j++)
  433.      if(GameGenieCode[i] == GameGenieTable[j]){
  434.      found ++;
  435.      
  436.      //Twirling Ternary operators to convert Game Genie to its equivalent Hex.
  437.         (found == 1) ? n0 = j : (found == 2) ? n1 = j :
  438.         (found == 3) ? n2 = j : (found == 4) ? n3 = j :
  439.         (found == 5) ? n4 = j : (found == 6) ? n5 = j :j;
  440.        
  441.        
  442.             (is_8_Char_GameGenie) ? (found == 7 ? n6 = j : found == 8 ? n7 = j : j) : j;
  443.              
  444.      }
  445.  }
  446.  
  447.  //Checking for Invalid Genie Codes.
  448.  return (found == (is_8_Char_GameGenie ? 8 : 6)) ? 1 : 0;
  449. }
  450.  
  451. //decodes GameGenieAddress
  452. int decodeGameGenieAddress()
  453. {
  454.  
  455.     int address = 0x8000 +
  456.                   ((n3 & 7) << 12)
  457.                   | ((n5 & 7) << 8) | ((n4 & 8) << 8)
  458.                   | ((n2 & 7) << 4) | ((n1 & 8) << 4)
  459.                   |  (n4 & 7)       |  (n3 & 8);
  460.  
  461.     return address;
  462.  
  463. }
  464.  
  465. //decodes GameGenievalue.
  466. //Decodes Value from 6 or 8-Char GameGenie Code.
  467. int decodeGameGenieValue(){
  468.    
  469.  int value;
  470.    
  471.     //Checking if it's 8-Char_GameGenie Code.
  472.     (is_8_Char_GameGenie == true)
  473.    
  474.  //Value of 8-Char GameGenie.
  475.     ? (value =
  476.              ((n1 & 7) << 4) | ((n0 & 8) << 4)
  477.             | (n0 & 7)       |  (n7 & 8))
  478.    
  479.         //Value of 6-Char GameGenie.
  480.     : (value =
  481.              ((n1 & 7) << 4) | ((n0 & 8) << 4)
  482.             | (n0 & 7)       |  (n5 & 8) );
  483.  
  484.  return value;
  485. }
  486.  
  487.  
  488. //Decodes Compare Value for 8-Char GameGenie Code.
  489. int decodeGameGenieCompare(){
  490.    
  491.           int  compare =
  492.              ((n7 & 7) << 4) | ((n6 & 8) << 4)
  493.             | (n6 & 7)       |  (n5 & 8);
  494.       return compare;      
  495.    
  496. }
  497.  
  498. //Check the GameGenieInput.
  499. int check_input(char * input)
  500. {
  501.  
  502.     int input_found = 0;
  503.     int input_index = 0;
  504.     int Table_index = 0;
  505.  
  506.     for(input_index = 0; input_index < strlen(input); input_index++)
  507.     {
  508.         for(Table_index = 0; Table_index < GAME_GENIE_TABLE_LEN; Table_index++)
  509.         {
  510.  
  511.             if(GameGenieInput[input_index] == GameGenieTable[Table_index])
  512.                 input_found++;
  513.         }
  514.     }
  515.  
  516. //Checking for Invalid Inputs.
  517.     return (input_found == strlen(input) ) ? 1 : 0;
  518. }
  519.  
  520.  
  521. //Check for Duplicate inputs.
  522. _Bool check_duplicates  (char str[])
  523. {
  524.  
  525.     static _Bool Input_has_dup = false; //Boolean to check duplicate.
  526.  
  527.     int str_index = 0,Table_index = 0,dup_count[GAME_GENIE_TABLE_LEN] = {0}; //Count for Every character from GameGenieTable.
  528.  
  529.  
  530.     //Checking Repeated Strings.
  531.     while (str[str_index] != '\0')
  532.     {
  533.  
  534.         for(Table_index = 0; Table_index < GAME_GENIE_TABLE_LEN; Table_index++)
  535.         {
  536.  
  537.             if (str[str_index] == GameGenieTable[Table_index]) //Comparing input characters to GameGenieTable characters.
  538.                 dup_count[Table_index]++; //Count Array of Duplicates if true.
  539.         }
  540.  
  541.         str_index++;
  542.     }
  543.  
  544.     //Checking if duplicates exist in input or not ? Later Removing them if needed.
  545.     for(str_index = 0; str_index < Table_index  ; str_index++)
  546.     {
  547.  
  548.         //If input has atleast 1 duplicate.
  549.         if(dup_count[str_index] > 1)
  550.         {
  551.             Input_has_dup = true; //Set Bool to True.
  552.             break; //No need to Search for more Duplicates.
  553.         }
  554.     }
  555.  
  556.     return Input_has_dup;
  557. }
  558.  
  559. //Remove Duplicates from Input using Hashing.
  560. //Time Complexity: O(n)
  561. char *remove_duplicates(char *str)
  562. {
  563.     int bin_hash[NO_OF_CHARS] = {0}; /* Binary hash to see if character is
  564.                                         already processed or not */
  565.  
  566.     int input_index = 0; /* index to  keep track of location of next
  567.                                                                                                                             character in input string */
  568.  
  569.     int result_index = 0; /* index to  keep track of location of
  570.                             next character in the resultant string */
  571.     char temp;
  572.  
  573.  
  574.     /* In place removal of duplicate characters*/
  575.     while (*(str + input_index))
  576.     {
  577.         temp = *(str + input_index);
  578.         if (bin_hash[temp] == 0)
  579.         {
  580.             bin_hash[temp] = 1;
  581.             *(str + result_index) = *(str + input_index);
  582.             result_index++;
  583.         }
  584.         input_index++;
  585.     }
  586.  
  587.     /* After above step string is stringiittg.
  588.        Removing extra iittg after string*/
  589.     *(str+result_index) = '\0';
  590.  
  591.     return str;
  592. }
  593.  
  594. //Checking if Input is in Lower Case.
  595. _Bool isInputLower(char *str){
  596.    
  597.     int index = 0;
  598.    
  599.     for(index = 0; index < strlen(str); index++){
  600.         if(islower(str[index]))
  601.          return true;
  602.     }
  603.        
  604.         return false;
  605. }
  606.  
  607. //Converts the Input to Capital case.
  608. void toUpperCase(char *str)
  609. {
  610.  
  611.     int index = 0;
  612.     char smallCase; //Hold small cases to compare
  613.  
  614.     while(str[index])
  615.     {
  616.         //Check for All small characters.
  617.         for(smallCase = 'a'; smallCase <= 'z'; smallCase++)
  618.  
  619.             if(str[index] == smallCase)
  620.                 str[index] -= 32; // 32 is difference between Capital and Small character's ASCII.
  621.  
  622.         index++;
  623.     }
  624.  
  625. }
  626.  
  627. //Get Length of GameGenie Code.
  628. int getGameGenieLen(){
  629.     return strlen(GameGenieInput);
  630. }
  631.  
  632. //Prints Title on Respective Files.
  633. void printFileTitle(){
  634.    
  635.     //For 6-Char GameGenie Codes.
  636.     fprintf(_fp_6Char_GG,"%s\n","/////////////////////////////////\n6-Character Game Genie Codes...\n////////////////////////////////");   
  637.    
  638.     //For 8-Char GameGenie Codes.
  639.     fprintf(_fp_8Char_GG,"%s\n","//////////////////////////////////\n8-Character Game Genie Codes...\n////////////////////////////////");
  640.    
  641.     //For Failed Game Genie Codes.
  642.     fprintf(_fp_failedCodes,"%s\n","//////////////////////////////////\nFailed Codes or Junk Data...\n////////////////////////////////");
  643.                                        
  644. }
Add Comment
Please, Sign In to add comment