Skip to content

Instantly share code, notes, and snippets.

@lovejavaee
Created February 18, 2020 18:19
Show Gist options
  • Save lovejavaee/76434975f7d617872939ab82be363195 to your computer and use it in GitHub Desktop.
Save lovejavaee/76434975f7d617872939ab82be363195 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef void (*msg_type)(void);
void msg_1() {
printf("You have done well in this assignment!\n");
}
void msg_2() {
printf("You need to work more on this assignment!\n");
}
msg_type decide(char *argument) {
msg_type answer;
char input[5];
char random[5];
srand(time(NULL));
sprintf(random, "%d", rand() % 10000);
answer = msg_2;
strcpy(input, argument);
if (strcmp(input, random) == 0) {
answer = msg_1;
}
return answer;
}
int main(int argc, char *argv[]) {
msg_type msg;
if (argc < 2) {
printf("usage: %s <number guess>\n", argv[0]);
exit(1);
}
msg = decide(argv[1]);
msg();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment