c array - warning: format not a string literal

后端 未结 6 1708
终归单人心
终归单人心 2020-12-25 09:45

I\'m attempting to learn C and already I\'ve run into an issue. I assume its trivial but I need to know it. I have written:

#include 
#include         


        
6条回答
  •  粉色の甜心
    2020-12-25 10:32

    The warning is caused by the compiler wanting the first argument of printf to be a string literal. It wants you to write this:

    printf("%s\n", str_a);
    

    This is because the first parameter of printf is the format string. The format arguments are then passed after that.

    Note: You can in fact use a variable as a format string, but you probably shouldn't do that. That's why the compiler issues a warning and not an error.

提交回复
热议问题