我完全喪失了這一個。我無法弄清楚爲什麼這不起作用。具有NULL終止符的簡單字符數組 - 除了當我輸出它時,它不會終止!fprintf字符串終止的心理障礙
int file_create(const char *path) {
//trying to trap situations where the path starts with /.goutputstream
char path_left_15[16];
strncpy(path_left_15, path, 15);
printf("%d\n", strlen("/.goutputstream")+1);
path_left_15[strlen("/.goutputstream")+1] = '\0';
printf("%d\n", strlen(path_left_15));
printf("path_left_15: %s\n", path_left_15);
//continue on...
}
這是我的輸出:
> 16
> 16
>/.goutputstream\B7<random memory stuff>
我想不通這是爲什麼不正確終止。我試着讓這個數組變長,但我每次都得到相同的結果。我正在失去理智!
有人看到了嗎?謝謝。
** f ** printf?你沒有傳遞文件指針。 – Kevin 2013-04-20 00:25:10
'NULL'是一個擴展爲空*指針*常量的宏。推測你的意思是「NUL終結者」,或者更好的是「終結者」。 – 2013-04-20 00:48:54
你說得對,凱文。我的意思就是printf。接得好。 – Alex 2013-04-20 03:39:28