| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 495 人关注过本帖
标题:求子串问题啊
取消只看楼主 加入收藏
小小小丹丹
Rank: 2
等 级:论坛游民
帖 子:26
专家分:13
注 册:2010-4-6
结帖率:62.5%
收藏
已结贴  问题点数:18 回复次数:2 
求子串问题啊
status SubString(HString pS1, int pos,int len){   //用sub返回串s的第pos个字符起长度为len的子串
   int i;
   printf("Please input the pos and length!\n ");
   scanf("%d%d",&pos,&len);                                                 //循环控制变量定义
   if(pos<1||pos>pS1.length||len<0||len>pS1.length-pos+1)     //pos位置不合法
     return(ERROR);
   if(Sub.ch)  free(Sub.ch);                              //释放串sub空间原有的数据                              
   if(!len){Sub.ch=NULL;Sub.length=0;}                    //返回长度为0,sub为空串
   else{
     Sub.ch=(char *)malloc(len * sizeof(char));           //为sub分配长度为len的空间
     for(i=0;i<pos+len-2;i++)                             //将pos后长度为len的子串赋给sub串
     Sub.ch=pS1.ch[pos-1+i];                              
     Sub.length=len;                                      //修改sub的串长
    };
return OK;
}求高手改下啊
搜索更多相关主题的帖子: return status 空间 
2010-05-25 16:13
小小小丹丹
Rank: 2
等 级:论坛游民
帖 子:26
专家分:13
注 册:2010-4-6
收藏
得分:0 
有道理再帮我看看这个啊
栈里函数的怎么调用
#include"stdio.h"
#include"stdlib.h"
#include"malloc.h"

#define STACK_INIT_SIZE 100;
#define STACKINCREMENT 10;

typedef struct
{
    int *base;
    int *top;
    int stacksize;
}SqStack;

typedef  int ElemType;

int InitStack(SqStack **S) //为栈S分配存储空间,并置S为空栈
{
    int size = STACK_INIT_SIZE;
    (*S) = (SqStack *)malloc(sizeof(SqStack));
    (*S)->base=(int *)malloc(size*sizeof(ElemType));
    if(!(*S)->base) return 0;
    (*S)->top=(*S)->base; //置栈S为空栈
    (*S)->stacksize=STACK_INIT_SIZE;
    return 1;
}
nt  GetTop(SqStack *S,int *e)  //若栈不空,则用e返回S的栈顶元素
{
    if(S->top==S->base) return 0;
    *e=*(S->top-1);
    return 1;
}
                                                                                                                  
int  Push(SqStack *S, int e) /*进栈函数,将e插入栈S中,并使之成为栈顶元素*/                                         
{                                                                                                                 
    if(S->top-S->base>=S->stacksize) /*栈满,追加存储空间*/                                                      
    {                                                                                                            
        int stackinvrement = STACKINCREMENT;                                                                     
        S->base=(ElemType *) realloc(S->base,                                                                     
            (S->stacksize+stackinvrement)*sizeof(ElemType));                                                      
        if(!S->base) return 0; /*存储分配失败*/                                                                  
        S->stacksize+=STACKINCREMENT;                                                                             
    }                                                                                                            
    *S->top++=e;                                                                                                  
    return 1;                                                                                                     
}                                                                                                                 
                                                                                                                  
int  Pop(SqStack *S,int *e)/*出栈函数,若栈S不空,则删除S的栈顶元素,用e返回其值*/                                   
{                                                                                                                 
    if(S->top==S->base) return 0;                                                                                 
    *e=*--S->top;                                                                                                
    return 1;                                                                                                     
}  
void OutputStack(SqStack *S)                                                                                      
{                                                                                                                 
    int *q,i=0;                                                                                                   
    q=S->top-1;                                                                                                   
    for(i=0;i<S->top-S->base;i++)                                                                                 
    {                                                                                                            
        printf("%d ",*q);q--;                                                                                    
    }                                                                                                            
}                                                                                                                 
                                                                                                                  
int main()                                                                                                        
{                                                                                                                 
    int a,b,c,d,e;                                                                                                
    SqStack *h;                                                                                                   
    InitStack(&h);                                                                                                
    printf("你要输入几个元素:\n");                                                                                
    scanf("%d",&a);                                                                                               
    printf("请输入你要的元素:\n");                                                                                
    for(b=0;b<a;b++)                                                                                             
    {                                                                                                            
        scanf("%d",&c);                                                                                          
        Push(h,c);                                                                                                
    }                                                                                                            
    OutputStack(h);                                                                                               
    GetTop(h,&e);                                                                                                  
    Pop(h,&e);                                                                                                   
    printf("返回的栈顶元素:%d\n",e);                                                                              
}
还有push,pop,Output,GetTop等函数怎么调用啊帮帮忙啊我调用函数好多弄不明白呢
2010-05-25 18:34
小小小丹丹
Rank: 2
等 级:论坛游民
帖 子:26
专家分:13
注 册:2010-4-6
收藏
得分:0 
我还是不会啊你能帮我调用一下么写给我看看啊
2010-05-25 20:18
快速回复:求子串问题啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017618 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved