您的位置:首页 > 其它

找出字符串的所有片段 c版

2018-08-15 22:26 91 查看
#include <stdio.h>
#include <string.h>
#include <malloc.h>
typedef struct {
char son[11];
} Elem;

int main(void) {
char str[10];
scanf("%s",str);
int len=strlen(str);
int N2=0;//子串的个数 : 1+2+3+...+n
for (int i=1;i<=len;i++) N2+=i;
Elem *exp=(Elem*)malloc(sizeof(Elem)*N2);
int count=0;
for (int i=1;i<=len;i++){
int j=0;
int m;
while (true){
m=j;//j 可以控制str从那里开始截取
for (int k=0;k<i;k++){
exp[count].son[k]=str[m++];

}
j++,count++;
if (m==len) break;
}

}
for (int i=0;i<N2;i++){
printf("%s\n",exp[i].son);
}
return 0;
}
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐