Advertisement
Guest User

woooohooooo

a guest
Sep 25th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define ROW 8
  6. #define COLUMN 8
  7.  
  8. int main()
  9. {
  10.     char* input = "8. R4xe4 h6";
  11.     char* whiteMove;
  12.     char* blackMove;
  13.     int copyFlag = 0;
  14.     int i = 0;
  15.     int k = 0;
  16.     int len = 0;
  17.  
  18.     // Allocate a buffer. For this, we will allocate it the same dimensions as input has.
  19.     len = strlen(input);
  20.     whiteMove = (char *)malloc(len);
  21.     blackMove = (char *)malloc(len);
  22.  
  23.     // Zero out the memory, for the same length of bytes obtained above.
  24.     // \0 is a null terimator. We use this to inform functions like printf that they have
  25.     // reached the end of the data and any data beyond it is garbage or unused.
  26.  
  27.     memset(whiteMove, '\0', len);
  28.     memset(blackMove, '\0', len);
  29.     // Loop through each character
  30.  
  31.     for (i = 0; i < len; i++)
  32.     {  
  33.         if (copyFlag == 0) // Have not found a blank space yet
  34.         {  
  35.             if (input[i] == ' ') // Is this a blank space?
  36.             {  
  37.                 copyFlag = 1; // Begin Copying
  38.             }
  39.         }
  40.         else if (copyFlag == 1) // Found a blank space, so copy
  41.         {  
  42.             if (input[i] != ' ')
  43.             {  
  44.                 whiteMove[k] = input[i]; // Copy current character to index k
  45.                 k++; // Move to next index.
  46.             }
  47.             else
  48.             {  
  49.                 break; // No more copying is needed
  50.                  break; // No more copying is needed
  51.              }
  52.          }
  53.      }
  54.  
  55.      i = 0;
  56.      k = 0;
  57.      copyFlag = 0;
  58.      for (i = 0; i < len; i++)
  59.      {
  60.          if (copyFlag < 2 )
  61.          {
  62.              if (input[i] == ' ')
  63.              {
  64.                  copyFlag++;
  65.              }
  66.  
  67.          }
  68.          else if (copyFlag == 2)
  69.          {
  70.              if (input[i] != ' ')
  71.              {
  72.                  blackMove[k] = input[i];
  73.                  k++;
  74.              }
  75.              else
  76.              {
  77.                  break;
  78.              }
  79.  
  80.          }
  81.      }
  82.      printf(whiteMove); // Display the message
  83.      printf("\n"); // new line
  84.      free(whiteMove); // Free the memory we allocated
  85.      printf(blackMove);
  86.      printf("\n");
  87.      free(blackMove);
  88.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement