#include<stdio.h>#include<string.h>#include<stdlib.h>#include<stdbool.h>#define BUF_len 1000#define INIT_str_ext 50#define WORDS_incr 5int main(void){char delimiters[]="\n\", .?!)(:;";char buf[BUF_len];size_t str_size=INIT_str_ext;char *pStr=(char*)malloc(str_size);*pStr='\0'; 這里給個\0是什么意思?沒看明白。printf("enter some prose with up to %d characrters per line.\n""Terminate input by entering an empty line:\n",BUF_len);
1 回答

慕哥6287543
TA貢獻1831條經驗 獲得超10個贊
char *pStr=(char*)malloc(str_size);這時pStr指向占用str_size個字節的堆空間。
*pStr='\0';給首地址賦0。
那么這時printf("%s", pStr);等就有意義,因為第一個就是\0。
反之沒有賦0,printf("%s", pStr)就會輸出直到遇到0或訪問內存出錯。
這是一個較好的編程習慣,在這里其實寫不寫都可以(建議寫)。
添加回答
舉報
0/150
提交
取消