|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
/* Example 6.4 Arrays of strings */
#include <stdio.h>
int main(void)
{
char str[][50] = {
"To be or not to be" ,
", that is the question"
};
int count[] = {0, 0}; /* Lengths of strings */
int i;
/* find the lengths of the strings */
for( i = 0 ; i<2 ; i++)
while (str[i][count[i]])
count[i]++;
/* Check that we have enough space for both strings */
if(sizeof str[0] < count[0] + count[1] + 1)这里明明就没有超过字符串40 却显示ou can't put a quart into a pint pot.");
printf("\nYou can't put a quart into a pint pot.");
else
{ /* Copy 2nd string to first */
count[1] = 0;
while((str[0][count[0]++] = str[1][count[1]++]));
printf("\n%s\n", str[0]); /* Output combined string */
}
return 0;
}
该贴已经同步到 空手套小白狼的微博 |
|