dimanche 1 novembre 2015

Setting up an if statement with characters?

Here is my code:

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

int main() 
{

    char input[99];
    int i, i2, i3, n;

    while(1) 
    {

    i = 0;
    i2 = 1;
    i3 = 2;
    n = 0;

        printf("I can recognize if you are laughing or not, please type in a string. Type \"bye\" to quit: ");

        scanf("%s", input);

        printf("\n");

        if(strcmp(input, "bye") == 0) 
        {
            printf("Bye now!\n");
            break;
        }

        int length_input = strlen(input);
    char h = h;
    char a = a;
    char o = o;
    char x = !;  

    printf("Your input is: %s\n", input);

        for(; i < length_input; (i+2)) 
        {

            if(input[i] !== h) // is not laughing? or to say: if input[i] =/= h then not laughing.
            {
                printf("You are not laughing...\n");
                i2 = length_input;
                n = 1;
                i = length_input;
                i3 = length_input;
            }

        }

    for(; i2< length_input; (i2+2))
    {

        if(input[i2] !== a || o || x) // is not laughing? or to say: if input[i] =/= a, o, or ! then not laughing.
        {
            printf("You are not laughing...\n");
            i2 = length_input;
            n = 1;
            i3 = length_input;
        }

    }

    for(; i3 < length_input; (i3+3)) 
    {
        if(input[i3] == x) //is laughing? or to say: if input[i2] = ! then laughing
        {
            printf("You are laughing!\n");
            i3 = length_input;
            n = 1;
        }   

    }

    if(n == 0)
    {
        printf("You are not laughing...\n");
    }


        printf("\n");        
    }
}

As the title says I think I am having issues mainly in my if statements. Specifically where it says input[i] !== h, input[i] !== a || o || x, etc. Any help to fix my code so that is functions is greatly appreciated.

Examples of what the code should reade are:

I can recognize if you are laughing or not, please type in a string: ha!

Your input is: ha!

You are laughing!

I can recognize if you are laughing or not, please type in a string: haha!

Your input is: haha!

You are laughing!

I can recognize if you are laughing or not, please type in a string: ho!

Your input is: ho!

You are laughing!

I can recognize if you are laughing or not, please type in a string: hohohaha!

Your input is: hohohaha!

You are laughing!

I can recognize if you are laughing or not, please type in a string: haa!

Your input is: haa!

You are not laughing...

I can recognize if you are laughing or not, please type in a string: ha!!

Your input is: ha!!

You are not laughing...

I can recognize if you are laughing or not, please type in a string: ha!ha

Your input is: ha!ha

You are not laughing...

I can recognize if you are laughing or not, please type in a string: bye

Bye now!

Aucun commentaire:

Enregistrer un commentaire