设置带有字符的if语句?

问题描述:

这里是我的代码:设置带有字符的if语句?

#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");   
    } 
} 

正如标题所说,我认为我有主要是在我的if语句的问题。特别是在输入[i]!== h的地方,输入[i]!== a || o || x等。任何帮助修复我的代码,这是功能非常感谢。的代码应该里德什么

的例子是:

,如果你在笑我可以识别或不能,请输入一个字符串: 哈哈!

您的输入是:哈!

你在笑!

,如果你在笑我可以识别或不能,请输入一个字符串: 哈哈!

您的输入是:哈哈!

你在笑!

,如果你在笑我可以识别或不能,请输入一个字符串: 嗬!

您的输入是:ho!

你在笑!

如果你或笑我不能够识别,请输入一个字符串: hohohaha!

你输入:hohohaha!

你在笑!

如果你或笑我不能够识别,请输入一个字符串: HAA!

您的输入是:haa!

你是不是笑...

,如果你在笑我可以识别或不能,请输入一个字符串: 哈!

您的输入是:ha!

你是不是笑...

如果你或笑我不能够识别,请输入一个字符串: 哈哈

你输入:哈哈

你是不是笑...

如果你或笑我不能够识别,请输入一个字符串: 再见

再见!

由于这看起来是C,所以您会想用!=代替!==。此外,如果您想查看变量x是否不等于变量y或变量z,则使用两个不同的比较,分别用& &分隔。例如:x!= y & & x!= z

+0

如何将x存储为'!'?我也有一个错误。 –

+0

你把它放在单引号中吗?从我在你的代码中看到的,你正在使用'char x =!',它与'char x ='!''不一样。事实上,我看到你对a和o做同样的事情。 –