链接两个字符串
我想问问注释里面的(4),在i+到5以后是怎么工作的,不讲这个的或者乱扯淡的垃圾请不要发言,谢谢程序代码:
#include<stdio.h> #include<string.h> int main() { char s1[80], s2[40]; int i = 0, j = 0; printf("Input s1:\n"); scanf_s("%s", s1, 80); printf("\n"); printf("Input s2:\n"); scanf_s("%s", s2, 40); while (s1[i] != '\0') //(1)这里只要s1[i] != '\0',i++;例如输入s1=123,s2=456,此时s1[2]=3,跳到(2) i++; while (s2[j] != '\0') //(2)和(1)类似 s1[i++] = s2[j++]; //(3)此时i++是从3即s1[3]开始+的,因为(1)中i的计数,一直加到5 s1[i] = '\0'; //(4)?这怎么实现?此时i是几,为什么? printf("\nThe new string is:\n"); printf("%s", s1); printf("\n"); return 0; }
[此贴子已经被作者于2016-12-28 15:47编辑过]