| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 366 人关注过本帖
标题:程序没有错误,但是不能运行,请大家指点下~
取消只看楼主 加入收藏
linruicsu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-28
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:0 
程序没有错误,但是不能运行,请大家指点下~
我用的是VC++6.O
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#define ERROR 0
#define OK 1
#define OVERFLOW -2
typedef struct{
        char *ch;
        int length;
}*HString;
 StrAssign(HString T,char *chars)
{
       int i,j;char *c;
       if (T->ch) free(T->ch);
       for (i=0,c=chars;*c;++i,++c);
       if (!i) {T->ch=NULL;T->length=0;}
       else {
            if(!(T->ch=(char*)malloc(i*sizeof(char))))
                           return ERROR;
            for (j=0;j<i;++j)
            T->ch[j]=chars[j];
            T->length=i;
       }
       return OK;
}

int StrLength(HString S)
{
    return S->length;
}

int StrCompare(HString S,HString T)
{
    int i;
    for(i=0;i<S->length&&i<T->length;++i)
    if(S->ch[i]!=T->ch[i])
    return S->ch[i]-T->ch[i];

}

 ClearString(HString S)
{
       if (S->ch) {free(S->ch);S->ch=NULL;}
       S->length=0;
       return OK;
}

 Concat(HString T,HString S1,HString S2)
{
       int i;
       if(T->ch) free(T->ch);
       if(!(T->ch=(char*)malloc((S1->length+S2->length)*sizeof(char))))
                return ERROR;
       for(i=0;i<S1->length;++i)
       T->ch[i]=S1->ch[i];
       T->length=S1->length+S2->length;
       for(i=0;i<S2->length;++i)
        T->ch[S1->length+i]=S2->ch[i];

       return OK;
}

 SubString(HString Sub,HString S,int pos,int len)
{
       int i;
       if(pos<1||pos>S->length||len<0||len>S->length-pos+1) return ERROR;
       if(Sub->ch) free(Sub->ch);
       if(!len)
       {
            Sub->ch=NULL;
            Sub->length=0;
       }
       else
       {
            Sub->ch=(char*)malloc(len*sizeof(char));
            for(i=0;i<len;++i)
            Sub->ch[i]=S->ch[pos+i-1];
            Sub->length=len;
       }
       return OK;
}

 StrInsert(HString S,int pos,HString T)
{
       int i;
       if(pos<1||pos>S->length+1) return ERROR;
       if(T->length) {
                    if(!(S->ch=(char *)realloc(S->ch,(S->length+T->length)*sizeof(char))))
                                    return ERROR;
                    for(i=0;i<S->length-pos+1;++i)
                    S->ch[S->length+T->length-1-i]=S->ch[S->length-1-i];
                    for(i=0;i<T->length;++i)
                    S->ch[pos-1+i]=T->ch[i];
                    S->length+=T->length;
       }
       return OK;
}

int  ShowString(HString S)
{
       int i;
       for(i=0;i<S->length;++i)
       printf("%c",S->ch[i]);

return OK;}
main()
{
         int i,pos,len;
        HString S1,S2,P,T,Sub=NULL;
        char s,*chars,*temp,*test;
       printf("请输入串S1:\n");
        scanf("%s",chars);
        StrAssign(S1,chars);
        ShowString(S1);
        printf("\n串的长度是%d!",StrLength(S1));
        printf("\n请输入串S2:");
        scanf("%s",temp);
        StrAssign(S2,temp);
        ShowString(S2);
        i=StrCompare(S1,S2);
        if(i<0)
        s='<';
        else if(i==0)
        s='=';
        else
        s='>';
        printf("串S1 %c 串S2!\n",s);
        Concat(T,S1,S2);
        printf("经过比较后的串为 T is:");
        ShowString(T);
        printf("\n请输入你所需要的位置和长度:");
        scanf("%d,%d",&pos,&len);
        SubString(Sub,T,pos,len);
        printf("子串是:");
        ShowString(Sub);
        printf("\n请插入模式串S2:\n");
        scanf("%s",test);
        StrAssign(P,test);
        printf("请输入你所要查找的位置:");
        scanf("%d",&pos);
        StrInsert(S2,pos,P);
        printf("T的操作结果为:");
        ShowString(S2);
      getch();
}
搜索更多相关主题的帖子: 运行 
2010-07-07 11:06
快速回复:程序没有错误,但是不能运行,请大家指点下~
数据加载中...
 
   



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

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