Using %s in C correctly - very basic level

后端 未结 5 949
庸人自扰
庸人自扰 2020-12-10 05:09

I know that %s is a string of characters, but I don\'t know how to use it. Can anyone provide me a very basic example of how its used and how its different from char ?

5条回答
  •  一整个雨季
    2020-12-10 05:14

    %s will get all the values until it gets NULL i.e. '\0'.

    char str1[] = "This is the end\0";
    printf("%s",str1);
    

    will give

    This is the end

    char str2[] = "this is\0 the end\0";
    printf("%s",str2);
    

    will give

    this is

提交回复
热议问题