Why does using the wrong format specifier in C crash my program on Windows 7?

前端 未结 5 1571
后悔当初
后悔当初 2020-12-11 14:56

My program is as follows;

#include 
#include 

int main()
{
        char string[] = \"Gentlemen start your engines!\";
                


        
5条回答
  •  抹茶落季
    2020-12-11 15:41

    You have a problem here printf("That string is %s characters long.\r\n", strlen(string));

    put

    printf("That string is %d characters long.\r\n", strlen(string)); %d because you want to printthe length of str (strlen returns number)

提交回复
热议问题