Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #define ROW 8
- #define COLUMN 8
- int main()
- {
- char* input = "8. R4xe4 h6";
- char* whiteMove;
- char* blackMove;
- int copyFlag = 0;
- int i = 0;
- int k = 0;
- int len = 0;
- // Allocate a buffer. For this, we will allocate it the same dimensions as input has.
- len = strlen(input);
- whiteMove = (char *)malloc(len);
- blackMove = (char *)malloc(len);
- // Zero out the memory, for the same length of bytes obtained above.
- // \0 is a null terimator. We use this to inform functions like printf that they have
- // reached the end of the data and any data beyond it is garbage or unused.
- memset(whiteMove, '\0', len);
- memset(blackMove, '\0', len);
- // Loop through each character
- for (i = 0; i < len; i++)
- {
- if (copyFlag == 0) // Have not found a blank space yet
- {
- if (input[i] == ' ') // Is this a blank space?
- {
- copyFlag = 1; // Begin Copying
- }
- }
- else if (copyFlag == 1) // Found a blank space, so copy
- {
- if (input[i] != ' ')
- {
- whiteMove[k] = input[i]; // Copy current character to index k
- k++; // Move to next index.
- }
- else
- {
- break; // No more copying is needed
- break; // No more copying is needed
- }
- }
- }
- i = 0;
- k = 0;
- copyFlag = 0;
- for (i = 0; i < len; i++)
- {
- if (copyFlag < 2 )
- {
- if (input[i] == ' ')
- {
- copyFlag++;
- }
- }
- else if (copyFlag == 2)
- {
- if (input[i] != ' ')
- {
- blackMove[k] = input[i];
- k++;
- }
- else
- {
- break;
- }
- }
- }
- printf(whiteMove); // Display the message
- printf("\n"); // new line
- free(whiteMove); // Free the memory we allocated
- printf(blackMove);
- printf("\n");
- free(blackMove);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement