鱼C论坛

 找回密码
 立即注册
查看: 2204|回复: 0

一个字符串问题,很简单我想不过来。

[复制链接]
发表于 2012-1-18 00:25:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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;
}




                               
登录/注册后可看大图
该贴已经同步到 空手套小白狼的微博
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-10 20:46

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表