我在尝试打印一个包含令牌(tok)的字符数组(存储)时遇到了一些问题。每当我打印数组时,我都会得到一个奇怪的符号。
while(1)
{
printf("repl>");
char storage [30];
char* tok;
char g;
char buffer[20];
int pos = 0, i;
size_t bufferlength = 20;
fgets(buffer,sizeof(buffer),stdin);
tok = strtok(buffer," ");
while (tok != NULL)
{
storage[pos] = tok;
tok = strtok(NULL," ");
pos++;
}
printf(" %c\n", storage[0]);
}