Anonymous Anonymous - 26 days ago
71 0

No description

C

interface.c

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>


int responder(char user_input[]){                                               //Function to communicate answer codes to board program

    time_t t;
    srand((unsigned) time(&t));                                                 //Initialize number generator

    char questionPart[6][4] = {"when", "will", "many", "who", "die", "exit"};

    char whenResponse[6][10] = {"today", "never", "tomorrow", "yesterday", "idk lel", "go away"};
    char willResponse[2][4] = {"Yes", "No"};
    char manyResponse[4][10] = {"NONE LOL", "42", "69", "420"};
    char whoResponse[9][15] = {"Clara", "Zach", "Jovi", "Daniella", "Me", "Yourself lol", "a drone", "a rover", "Elon Musk"};
    char dieResponse[5][15] = {"by train", "by plane", "by axe", "bad sushi", "spicy memes"};

    for (size_t i = 0; i < 6; i++) {
        if(strstr(user_input,questionPart[i]) != NULL){
            printf("\n\nQuestion Contains: %s\n", questionPart[i]);
            printf("Answer Code: %d\n", i);

            switch (i) {
                case 0:
                    printf("Well, let me think about that....I think it will be %s\n", whenResponse[rand() % 6]);
                    break;
                case 1:
                    printf("Well, let me think about that....I think it will be %s\n", willResponse[rand() % 2]);
                    break;
                case 2:
                    printf("Well, let me think about that....I think it will be %s\n", manyResponse[rand() % 4]);
                    break;
                case 3:
                    printf("Well, let me think about that....I think it will be %s\n", whoResponse[rand() % 9]);
                    break;
                case 4:
                    printf("Well, let me think about that....I think it will be %s\n", dieResponse[rand() % 5]);
                    break;
                case 5:
                    printf("Goodbye human!\n");
                    return 0;
            }
        }
    }
    return 0;
}

int main(int argc, char const *argv[]) {

    printf("Enter Question to Answered by the Board of Ouija,\nplease type in lowercase alright, I'm not a sentient AI:\n");

    char user_input[200];                                                       //Character Array to store input
    fgets(user_input, sizeof(user_input), stdin);                               //Gets input
    int size = strlen(user_input);

    if (size && ('\n' == user_input[size-1])){                                  //Removews new line character
            user_input[size-1] = '\0';
    }
    responder(user_input);                                                       //Single function call                                      

    return 0;
}