How to use strcat() function?

后端 未结 2 707
离开以前
离开以前 2021-01-15 06:15

I am very new in C language. I was trying to use strcat function.

#include 
#include 

int main(int argc, const char *argv[])          


        
2条回答
  •  遥遥无期
    2021-01-15 06:54

    Both of the code snippet invoke undefined behavior. In the first snippet s1 has not enough space to hold any other character than six characters.
    In the second snippet you are trying to modify a string literal. Any attempt to modify a string literal lead to undefined behavior.

    Read strcat man page:

    [...] The strings may not overlap, and the dest string must have enough space for the result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs.

提交回复
热议问题