Error : format'%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]

后端 未结 3 1060
半阙折子戏
半阙折子戏 2021-01-24 10:17

I am currently trying to do my own shell, and it has to be polyglot. So I tryed to implement a function that reads the lines in a .txt file.

#include 

        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-24 11:16

    Let's take a closer look on the problematic line:

    printf("%s\n%s\n", aMsg[HI], aMsg[QUIT]);
    

    The string you would like to print expects 2 string parameters. You have aMsg[HI] and aMsg[QUIT]. These two are pointing to a char, so the result is one character for each. All char variables can be interpreted as a character or as a number - the character's ID number. So I assume the compiler resolves these as int types, thus providing you that error message.
    As one solution you merely use %c instead of %s.

    However, I suspect you want to achieve something else.

提交回复
热议问题