静态数组实现求子串--作业0401--实验三(串)
来源:互联网 发布:php exec java 不执行 编辑:程序博客网 时间:2024/06/13 21:39
获取子串时,输入空格就会有乱码,倒腾半天才知道接受母串时出错,cin.get(S,MAX_STRLEN); 不能接受空格回车之类的,gets()可以实现。小问题,害的自己狂晕。还是基础不行啊。
#include <stdio.h>用静态数组实现求子串(SubString)操作。从屏幕输入:
主串"Life is like a box of chocolate!"
子串的位置
子串长度
输出子串"a box of chocolate!"。 - #include <iostream.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX_STRLEN 255
- typedef char SString[MAX_STRLEN+1];
- int SubString (SString &Sub,SString S,int pos,int len)
- {
- if (pos<1||pos>S[0]||len<0||len>S[0]-pos+1)
- {
- cout<<"Error"<<endl;
- return 0;
- }
- for (int i=1;i<=len;i++)
- {
- Sub[i]=S[pos+i-1];
- }
- Sub[0]=len;
- Sub[i]='/0';
- return 1;
- }
- int main()
- {
- char Sub[MAX_STRLEN+1];
- int pos,len;
- char S[MAX_STRLEN+1];
- for (int i=0;i<MAX_STRLEN;i++)
- {
- cout<<"SubString.cpp/n=============/n/n"<<endl;
- cout<<"Please input the main String:"<<endl;
- gets(S);
- //cin.get(S,MAX_STRLEN);
- cout<<"Please input the position and length of SubString:"<<endl;
- cout<<"position="<<endl;
- cin>>pos;
- cout<<"length="<<endl;
- cin>>len;
- if(SubString(Sub,S,pos,len))
- {
- cout<<"The SubString is_="<<Sub+1<<endl;
- //cout<<"SubString.length= "<<Sub[0]<<endl;
- printf("SubString.length= %d/n",Sub[0]);
- }
- getchar();
- Sub[i]=NULL;
- S[i]=NULL;
- }
- return 0 ;
- }
- 静态数组实现求子串--作业0401--实验三(串)
- 实验三的实验作业
- DLUT C++上机作业(实验三)
- 实验三课后作业
- 实验三作业
- c++实验三作业
- 【数据结构作业】实现任意三种静态或动态查找
- 【数据结构作业】实现任意三种静态或动态查找
- 【JAVA】上机实验三作业
- 栈的三种实现(静态数组、动态数组及指针)
- C++第四次实验:项目二、三、四(作业)
- 把我的 C 作业贴出来 实验三 数组——1
- 把我的 C 作业贴出来 实验三 数组——2
- 【数据结构作业】实验三 单链表的基本操作(必做,设计性实验,4学时)
- 第二周实验作业之三、四
- 静态数组实现队列(C语言)
- 静态数组实现堆栈
- 静态数组实现栈
- LVS+HA
- test
- Webalizer配置文件中文版
- 使用Linux实现负载均衡
- 集群LVS实战解析
- 静态数组实现求子串--作业0401--实验三(串)
- LVS集群学习笔记详解
- LVS大全
- linux下nfs的配置
- Linux下NFS的配置与注意的问题
- 使用负载均衡技术建设高负载的网络站点
- 网络负载平衡转发技术简介
- 开发大型高负载类的网站应用的几个要点(转)
- RedhatAS4.2 安装集群LVS