ibennz

GetValueOfKeyArray

Apr 22nd, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. //fixed issue with extra chars and new lines.
  2. char* GetValueOfKeyArray(char* _array, char* keyname)
  3. {
  4.     char *output = (char*)malloc(0);
  5.  
  6.     for (size_t i = 0; i < strlen(_array); i++)
  7.     {
  8.         if (_array[i] == keyname[0])
  9.         {
  10.             char* t_array = (char*)malloc(strlen(keyname) + 1);
  11.             memcpy(t_array, _array + i, strlen(keyname));
  12.             t_array[strlen(keyname)] = '\0';
  13.            
  14.             if (strcmp(t_array, keyname) == 0)
  15.             {
  16.                 int size = 0;
  17.                 char* t_output = (char*)malloc(strlen(_array) - strlen(t_array) - i + 1);//(char*)realloc(output, strlen(_array) - strlen(t_array) - i + 1);
  18.                 memcpy(t_output, _array + strlen(t_array) + i + 1, strlen(_array) - strlen(t_array) - i + 1);
  19.                 for (size_t i = 0; i < strlen(t_output); i++)
  20.                 {
  21.                     size = i;
  22.                     output = (char*)realloc(output, i);
  23.                     if (t_output[i] == '\n')
  24.                         break;
  25.                 }
  26.                
  27.                 memcpy(output, t_output, size);
  28.                 output[size] = '\0';
  29.                 return output;
  30.             }
  31.         }
  32.     }
  33.     return "failed you dipshit";
  34. }
Advertisement
Add Comment
Please, Sign In to add comment