<分区>
有人可以解释为什么这不能正常工作吗?我得到 stack{0 through 4] 与 stack[4] 中的内容相同
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int stack_pointer = 0;
char *stack[30]; //MAX NUMBER OF VALUES IN STACK IS 30
int main(int argc, char** argv) {
char command_line[256];
while(stack_pointer < 5) { //Just store 5 inputs
printf("repl> ");
scanf("%s",command_line);
stack[stack_pointer] = command_line;
stack_pointer++;
}
int i = 0;
for(i = 0; i<5; i++) {
printf("stack[%d] = %s\n", i, stack[i]);
}
}
例如)
回复1
回复> 2
回复> 3
回复> 4
回复> 5
堆栈[0] = 5
堆栈[1] = 5
堆栈[2] = 5
堆栈[3] = 5
堆栈 [4] = 5