0

I'm currently trying to make a small 'Virtual Assistant' in C; very basic. But I'm encountering a couple errors which outputs error: incompatible types when assigning to type 'char[550]' from type 'char *'; or something like that.

Here is my code:

int main()
{
    char userName[35];
    char qInput[550];

    printf("Hi! What's your name?\n\a");
    scanf("%s", userName);

    printf("\nHello, %s! My name is EDI. I'm a friendly piece of AI you can talk to!\n\n\a", userName);
    printf("\nWhat would you like to ask me? Please keep in mind to use proper spelling \nor I won't understand the question.\n\a");

    scanf("%s", qInput);

    //what's your name?

    if(qInput = "What's your name"){
        printf("My name is EDI!");
        scanf("%s", qInput);
    } else if(qInput = "What's your name?"){
        printf("My name is EDI");
        scanf("%s", qInput);
    } else if(qInput = "Whats your name?"){
        printf("My name is EDI");
        scanf("%s", qInput);
    } else if(qInput = "What's your name"){
        printf("My name is EDI");
        scanf("%s", qInput);

    //age

    } else if(qInput = "How old are you?"){
        printf("I was born like eight minutes ago...");
        scanf("%s", qInput);
    } else if(qInput = "How old are you"){
        printf("I was born like eight minutes ago...");
        scanf("%s", qInput);
    } else if(qInput = "What is your age?"){
        printf("Eight or so minutes old.. Give or take");
        scanf("%s", qInput);
    } else if(qInput = "What is your age"){
        printf("Eight or so minutes old.. Give or take");
        scanf("%s", qInput);
    }
}

Please help me out! I am very new to C and would like to keep learning new things and new techniques. What can I change to make this work the way it should? I'm experienced with php, so I understand the if / else side of things..

Thanks!

  • `=` is assignment. `==` is comparison, but doesn't do what you want on C strings, see the linked question for that. – Mat Sep 27 '15 at 08:37

1 Answers1

1

First of all, = is assignement, == is comparison operator in C.

That said, you cannot compare strings using the == operator, like you did in

 if(qInput = "What's your name")  //note: not even == here.

You've to make use of strcmp() and check the return value to check the equality.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261