控制台警告if语句不起作用

时间:2015-03-09 16:07:27

标签: c

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

int main()
{
    char buffer[1024];
    printf("Hello\n");
    printf("What would you like to search\n");
    printf("Here are the options\n");
    printf("s : How are you\n");
    printf("c : What would you like to search\n");

    scanf("%s",&buffer);

    if(buffer == 's')
        printf("iam fine\n");
    else if (buffer == 'c')
        printf("What would you like to search\n");

    fgets(buffer, sizeof buffer, stdin);
    system(buffer);
    return 0;
}

控制台错误(程序无法正常运行)

C:\Users\sc\Documents\ForumCode\test\foo.c|12|warning: format '%s' expects type 'char *', but argument 2 has type 'char (*)[1024]'|
C:\Users\sc\Documents\ForumCode\test\foo.c|13|warning: comparison between pointer and integer|
C:\Users\sc\Documents\ForumCode\test\foo.c|15|warning: comparison between pointer and integer|

||=== Build finished: 0 errors, 3 warnings ===|

2 个答案:

答案 0 :(得分:1)

它应该是scanf(“%s”,缓冲区)

答案 1 :(得分:0)

您的buffer变量是一个字符数组,但在if语句中,您尝试将此数组与单个字符进行比较。

也许您正在寻找的是if (buffer[0] == 's')