Skip to content

Instantly share code, notes, and snippets.

@mikeymop
Last active February 4, 2019 01:41
Show Gist options
  • Save mikeymop/c333e413f4d0245e377f353773e8db5a to your computer and use it in GitHub Desktop.
Save mikeymop/c333e413f4d0245e377f353773e8db5a to your computer and use it in GitHub Desktop.
#include <stdio.h>
/*
Create Codebreaker.
./codebreaker [4 digit code] eg. ./codebreaker BGGY
Player 2 has 12 tries to guess the code.
enum Color {
B = "Blue",
G = "Green",
O = "Orange",
P = "Purple",
R = "Red",
Y = "Yellow"
}
*/
void testCode(char* c, char* g, int numGuesses) {
//take the color code into c
for(int i = 0; g[i]!= '\0'; ++i) {
//check if g is in c
if(c[i] == g[i]) {
printf("Found a match");
}
}
//iterate across c
//compare it to index of code[]
//if index matches increase
//feedback: print number of guesses
printf("Feedback: ");
};
char* prompt(char* guess, int tries) {
printf("\nAvailable colors: (B)lue (G)reen (O)range (P)urple (R)ed (Y)ellow\n\n");
printf("No. Guesses Left: %d", tries);
printf("\nEnter your guess: ");
scanf("%5s", &guess);
return guess;
}
#define MAX_GUESSES 12;
int main(int argc, char *argv[]) {
char guess[5];
char *code[5];
int numPosition;
int numExisting;
int tries = MAX_GUESSES;
if(argc < 2) {
printf("Please pick a four-color code using the provided colors");
return 1;
} else if(argc == 2) {
*code = argv[1];
printf("Your code is %s\n", *code);
//return 2;
}
prompt(guess, tries);
printf("%s", guess);
testCode(code, guess, tries);
return 0;
}
$ gcc -g cb.c
cb.c: In function ‘main’:
cb.c:63:14: warning: passing argument 1 of ‘testCode’ from incompatible pointer type [-Wincompatible-pointer-types]
testCode(code, guess, tries);
^~~~
cb.c:18:21: note: expected ‘char *’ but argument is of type ‘char **’
void testCode(char* c, char* g, int numGuesses) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment