1. 程式人生 > >C中無警告輸出size_t的值

C中無警告輸出size_t的值

  雖然警告沒什麼關係,吾能去掉的都儘量去掉。比如以下程式碼編譯有警告:

printf("responsed %u:%s\n", strlen(response), response);


gh_http.c:288:12: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
     printf("responsed %u:%s\n",strlen(response),response);

  怎麼解決?改為%zu即可。

printf("responsed %zu:%s\n", strlen(response), response);