I'm creating two programs that form a game and will be communicating with each other where one of them is essentially a user, but I'm starting off with building one and typing myself to this first program.
I want to input commands such as 'turn d1d2d3d4d5d6' (where the di are dice rolls), 'rerolled d1d2d3d4d5d6' and so forth, theres a bunch of commands. I want my program called player to take these commands and they'll do something with it.
Just to begin with I'm trying to take the input using stdin and putting it in array, then checking the array to see if its a valid command. However I can't seem to use fgetc and the array correctly. What i'm doing currently is just to take the input, put into an array and print it.
I don't actually want it to be 128 size array, I want it to be completely adjustable but I don't know how to do this with fgets. The if loop to check if its NULL is to find out if an array is empty but that's defintely wrong, not sure what to put in place there.
while(1){
int i = 1;
char* command[128];
fgets(command, 128, stdin);
for (i=0; i < 128; i++){
if (command[i] == NULL){
printf("%c\n", command[i]);
}
}
return 0;
}
So to be specific my main goal right now is take a command such as 'eliminated p' from the user and command becomes command=["eliminated","p"]