user-0 提问: C语言的gets（）问题！

回复:
user: user-0
content: 我明白怎么回事了 感谢赵4老师！

user: user-0
content: 引用 5 楼 zhao4zhong1 的回复://1个长度为N的字符串a_str是N+1个字符的数组 char a_str[N+1]; //10个长度为N的字符串ten_str是10个（N+1个字符的数组）组成的数组 char ten_str[10][N+1];    我搞不明白的就是 我定义的是char *p = max;     gets(p+i++);  从max[0] 开始每次都输入字符串“aaa”然后回车（自动附上‘\0’） 到max[9]的时候 输入完毕 回车 也没越界啊！为什么会错误！而且我用的是指针，按理上来说指针指向了p[9]的空间往里面存字符串不可能会照成这样的情况啊？这种输入方式和char max="......"不是一样的吗？我在qt creator下试了完美通过 表示完全蒙了！  是不是我哪理解错了？

user: user-1
content: //1个长度为N的字符串a_str是N+1个字符的数组 char a_str[N+1]; //10个长度为N的字符串ten_str是10个（N+1个字符的数组）组成的数组 char ten_str[10][N+1];

user: user-0
content: char max[10];//里面最多保存9个半角字符和一个末尾的'\0'，存不下10个字符串。   不是很明白！每个字符串末尾不是已经有‘\0’了吗？  为什么还要在max[10]在存个‘\0’   能解释在详细点吗？  我表示一头雾水啊！

user: user-1
content: 楼上的代码怎么不全呢？ #include <stdio.h> #include <string.h> int main() {     int i = 0,j;     char strs[10][8];     char *p = &strs[0][0];     puts("Please enter 10 strings");     while (i<10) {         printf("strs [%d] = Continue input: ",i);         fflush(stdout);         rewind(stdin);         fgets(p,8,stdin);         if ('\n'==p[strlen(p)-1]) p[strlen(p)-1]=0;         i++;         for (j=0;j<i;j++) {             printf("strs [%d] = [%s]\n",j,strs[j]);         }         p+=8;     }     return 0; } //Please enter 10 strings //strs [0] = Continue input: 1234567890 //strs [0] = [1234567] //strs [1] = Continue input: //strs [0] = [1234567] //strs [1] = [] //strs [2] = Continue input: a //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = Continue input: ab //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = Continue input: abc //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = Continue input: X //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = Continue input: XYZ //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = Continue input: 哈哈 //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = [哈哈] //strs [8] = Continue input: !@#$%^&*() //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = [哈哈] //strs [8] = [!@#$%^&] //strs [9] = Continue input: end //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = [哈哈] //strs [8] = [!@#$%^&] //strs [9] = [end] //

user: user-1
content: char max[10];//里面最多保存9个半角字符和一个末尾的'\0'，存不下10个字符串。  崩溃的时候在弹出的对话框按相应按钮进入调试，按Alt+7键查看Call Stack即“调用堆栈”里面从上到下列出的对应从里层到外层的函数调用历史。双击某一行可将光标定位到此次调用的源代码或汇编指令处，看不懂时双击下一行，直到能看懂为止。  其实电脑开机后物理内存的每个字节都是可读写的，从来不会因为所谓的new、delete或malloc、free而被创建、销毁。区别仅在于操作系统内存管理模块在你读写时是否能发现并是否采取相应动作而已。操作系统管理内存的粒度不是字节而是页，一页通常为4KB。 #include <stdio.h> #include <string.h> int main() {     int i = 0,j;     char strs[10][8];     char *p = &strs[0][0];     puts("Please enter 10 strings");     while (i<10) {         printf("strs [%d] = Continue input: ",i);         fflush(stdout);         rewind(stdin);         fgets(p,8,stdin);         if ('\n'==p[strlen(p)-1]) p[strlen(p)-1]=0;         i++;         for (j=0;j<i;j++) {             printf("strs [%d] = [%s]\n",j,strs[j]);         }         p+=8;     }     return 0; } //Please enter 10 strings //strs [0] = Continue input: 1234567890 //strs [0] = [1234567] //strs [1] = Continue input: //strs [0] = [1234567] //strs [1] = [] //strs [2] = Continue input: a //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = Continue input: ab //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = Continue input: abc //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = Continue input: X //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = Continue input: XYZ //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = Continue input: 哈哈 //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = [哈哈] //strs [8] = Continue input: !@#$%^&*() //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = [哈哈] //strs [8] = [!@#$%^&] //strs [9] = Continue input: end //strs [0] = [1234567] //strs [1] = [] //strs [2] = [a] //strs [3] = [ab] //strs [4] = [abc] //strs [5] = [X] //strs [6] = [XYZ] //strs [7] = [哈哈] //strs [8] = [!@#$%^&] //strs [9] = [end] //

user: user-0
content: 求回答啊！求顶起啊！