三木社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 383|回复: 0
打印 上一主题 下一主题

C语言数据结构-main4-2.c

[复制链接]

1562

主题

1564

帖子

4904

积分

博士

Rank: 8Rank: 8

积分
4904
跳转到指定楼层
楼主
发表于 2017-9-1 08:43:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. /* main4-2.c 检验bo4-2.c的主程序 */
  2. #include"c1.h"
  3. #include"c4-2.h"
  4. #include"bo4-2.c"
  5. void main()
  6. {
  7.    int i;
  8.    char c,*p="God bye!",*q="God luck!";
  9.    HString t,s,r;
  10.    InitString(&t); /* HString类型必需初始化 */
  11.    InitString(&s);
  12.    InitString(&r);
  13.    StrAssign(&t,p);
  14.    printf("串t为: ");
  15.    StrPrint(t);
  16.    printf("串长为%d 串空否?%d(1:空 0:否)\n",StrLength(t),StrEmpty(t));
  17.    StrAssign(&s,q);
  18.    printf("串s为: ");
  19.    StrPrint(s);
  20.    i=StrCompare(s,t);
  21.    if(i<0)
  22.      c='<';
  23.    else if(i==0)
  24.      c='=';
  25.    else
  26.      c='>';
  27.    printf("串s%c串t\n",c);
  28.    Concat(&r,t,s);
  29.    printf("串t联接串s产生的串r为: ");
  30.    StrPrint(r);
  31.    StrAssign(&s,"oo");
  32.    printf("串s为: ");
  33.    StrPrint(s);
  34.    StrAssign(&t,"o");
  35.    printf("串t为: ");
  36.    StrPrint(t);
  37.    Replace(&r,t,s);
  38.    printf("把串r中和串t相同的子串用串s代替后,串r为:\n");
  39.    StrPrint(r);
  40.    ClearString(&s);
  41.    printf("串s清空后,串长为%d 空否?%d(1:空 0:否)\n",StrLength(s),StrEmpty(s));
  42.    SubString(&s,r,6,4);
  43.    printf("串s为从串r的第6个字符起的4个字符,长度为%d 串s为: ",s.length);
  44.    StrPrint(s);
  45.    StrCopy(&t,r);
  46.    printf("复制串t为串r,串t为: ");
  47.    StrPrint(t);
  48.    StrInsert(&t,6,s);
  49.    printf("在串t的第6个字符前插入串s后,串t为: ");
  50.    StrPrint(t);
  51.    StrDelete(&t,1,5);
  52.    printf("从串t的第1个字符起删除5个字符后,串t为: ");
  53.    StrPrint(t);
  54.    printf("%d是从串t的第1个字符起,和串s相同的第1个子串的位置\n",Index(t,s,1));
  55.    printf("%d是从串t的第2个字符起,和串s相同的第1个子串的位置\n",Index(t,s,2));
  56. }
复制代码


回复

使用道具 举报

Archiver|手机版|小黑屋|三木电子社区 ( 辽ICP备11000133号-4 )

辽公网安备 21021702000620号

GMT+8, 2025-12-8 00:51 , Processed in 0.024082 second(s), 23 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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