| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 386 人关注过本帖
标题:谁能帮我修改一下(将插入函数修改成替换函数) 求帮助!!
取消只看楼主 加入收藏
hongshuai567
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2012-5-29
结帖率:50%
收藏
 问题点数:0 回复次数:0 
谁能帮我修改一下(将插入函数修改成替换函数) 求帮助!!
void SearchWord(char *str1,LinkList* temp)         
{
    char Data[20] ;
    int i,j,k=0,sum=0;
    int l=1;
    temp=head->next;
    strcpy(Data,str1);
   
    for(i=0;i<=NUM;i++)
    {
        for(j=0;j<80;j++)
        {
            if((temp->data[j])==Data[k]) k++;
            else if(Data[k]!='\0')
            {
                j=j-k;
                k=0;
            }
            if(Data[k]=='\0')
            {
            sum++;
            j=j-k+1;
            printf("\t\t第%d次出现在第%d行第%d列\n",l,i+1,j+1);
            l++;
            
            k=0;
            continue;}
        }
        temp=temp->next;
    }
    printf("\t\t\t字符串总共出现次数为:%d\n\n",sum);
    C=sum;   
    N=i*80+j;
}


void DeleteWord(char *str2)                    
{    char Data[20];
    LinkList *temp,*term;
    int i,j,k,m,y,num;

     strcpy(Data,str2);

    for(y=0;y<C;y++)
    {
        num=80;
        k=0,m=0;
        temp=head;
        for(i=0;i<=NUM;i++)
        {
            term=temp;
            temp=temp->next;
            for(j=0;j<80;j++)
            {
                if((temp->data[j])==Data[k]) k++;
                else if(Data[k]!='\0') {j=j-k;k=0;}
                if(Data[k]=='\0')
                {
                    num=j;
                    break;
                }
            }
            if(num<80) break;
        }
        for(;i<=NUM;i++)
        {
            for(;j<80;j++)
            {
                if(j+1<k)
                {
                    term->data[80-k+num]=temp->data[j+1];
                }
                else
                    temp->data[j-k+1]=temp->data[j+1];
            }
            term=temp;
               temp=temp->next;
                 j=0;
        }
    }
   
}

LinkList * InsertWord(LinkList *temp)
{   
    char Data[20];
    int h,l;
   
    printf("\n\t\t请输入要插入的字符或字符串:");
    getchar();
    gets(Data);

    printf("\n\t\t当前文章内容为:");
    PrintWord();

    printf("\n\t\t请输入要插入的行:");
    scanf("%d",&h);
    printf("\n\t\t请输入要插入的列:");
    scanf("%d",&l);

    int i=(h-1)*80+l;

    LinkList *a;

    int n=strlen(Data);
    int m ;
    int insertRow=i/80+1;
    int row=temp->row;
    int j;
    if(insertRow==row)
    {   
        for(m=temp->length-1;m>=(i%80)&&n>0;m--)
            temp->data[m+n]=temp->data[m];   
        for(m=(i%80),j=0;m<n+(i%80);m++,j++)
        {
            temp->data[m]=Data[j];        
        }
    }
    else
    {   
        int r=0;
        for(int p=insertRow; p<row;p++)
        {
            if(p == insertRow)
               r=0;
             else
                r=n;
            
            for(m=temp->length-1-r;m>=0&&n>0;m--)
            temp->data[m+n]=temp->data[m];
            a=temp;   
            temp = temp->pre;
            temp->length = 80;
            for(m = temp->length-n,j=0;m<temp->length;m++,j++)
                a->data[j]=temp->data[m];
        }
        for(m=temp->length-n-1;m>=(i%80);m--)
            temp->data[m+n]=temp->data[m];
        for(m=(i%80),j=0;m<(i%80)+n;m++,j++)
            temp->data[m] =Data[j];
        
    }
    return temp;
}

void Bmenu(LinkList *temp)
{  
    char str1[20];
    char str2[20];
    int a;
do
{
    HeadWord();
printf("\n\t\t**************************************************\n");
printf("\t\t****            文章内容处理菜单                ****\n");
printf("\t\t****************************************************\n");
printf("\t\t****    1、查找文章中的字符或者字符串           ****\n");
printf("\t\t****    2、删除文章中的字符或者字符串           ****\n");
printf("\t\t****    3、向文章中插入字符或者字符串           ****\n");
printf("\t\t****    4、显示当前文章内容                     ****\n");
printf("\t\t****    5、返回主菜单                           ****\n");
printf("\t\t****    6、直接退出系统                         ****\n");
printf("\t\t****************************************************\n");
printf("\t\t    请选择:");
int f=0;
loop1:f=scanf("%d",&a);  //如果输入无效,scanf会返回0
    if(!f)
    {
    fflush(stdin); //清空缓冲区
         printf("无效字符,请重新输入:");
    goto loop1;
    }
    if(a>0&&a<=6)
        printf("输入正确!");
    else
        {
        printf("无效数字,请重新输入:");
        goto loop1;
        }

switch(a)
{
case 1:   
           system("cls");
           HeadWord();
           printf("\t\t\t请输入您需要查找的字符或字符串:");
           getchar();
           gets(str1);
           SearchWord(str1,temp);
           printf("按回车键继续·····");
            getchar();
            getchar();
            system("cls");
           break;
case 2:
           system("cls");
           HeadWord();
           printf("\t\t\t请输入您需要删除的字符或字符串:");
           getchar();
           gets(str2);
           SearchWord(str2,temp);
           DeleteWord(str2);
           printf("\t\t\t删除 %s 后的文章为:",str2);
           PrintWord();
           printf("按回车键继续·····");
            getchar();
            getchar();
            system("cls");
           break;
case 3:
           system("cls");
           HeadWord();
           InsertWord(temp);
           printf("\t\t\t插入字符或字符串后文章为:");
           PrintWord();
           printf("按回车键继续·····");
            getchar();
            getchar();
            system("cls");
           break;
case 4:
           system("cls");
           HeadWord();
           PrintWord();
           printf("按回车键继续·····");
            getchar();
            getchar();
            system("cls");
           break;
}
if(a==5)  
{
    system("cls");
    break;
}
if(a==6)  exit(0);   

}while(1);        

}

void AboutWord()
{
            printf("\n\n\t\t                                            \n");
            printf("\t\t****************************************************\n");
            printf("\t\t**  本系统由电子商务11-1班李鸿帅,张莹,张蕾蕾制作**\n");
            printf("\t\t****************************************************\n");
            printf("\n");
}

void menu(LinkList *temp)
{
   
int t;
do{
HeadWord();
printf("\n");
printf("\t\t****************************************************\n");
printf("\t\t****                 主菜单                     ****\n");
printf("\t\t****************************************************\n");
printf("\t\t****        1、文章内容输入                     ****\n");
printf("\t\t****        2、显示当前文章内容                 ****\n");
printf("\t\t****        3、进入文章内容统计菜单             ****\n");
printf("\t\t****        4、进入文章内容处理菜单             ****\n");
printf("\t\t****        5、关于                             ****\n");
printf("\t\t****        6、退出文本编辑器                   ****\n");
printf("\t\t****************************************************\n");
printf("\t\t****    注:第一次运行本程序时请选择1号功能     ****\n");
printf("\t\t****************************************************\n");

printf("  \t\t  请选择:");
int f=0;
loop1:f=scanf("%d",&t);  //如果输入无效,scanf会返回0
    if(!f)
    {
    fflush(stdin); //清空缓冲区
         printf("无效字符,请重新输入:");
    goto loop1;
    }
    if(t>0&&t<=6)
        printf("输入正确!");
    else
        {
        printf("无效数字,请重新输入:");
        goto loop1;
        }


switch(t)
{  
    case 1:  
             system("cls");
             HeadWord();
             temp=CreatWord();
             break;
    case 2:  
             system("cls");
             PrintWord();
             printf("\n");
             printf("按回车键继续·····");
             getchar();
             getchar();
             system("cls");
             break;
    case 3:
             system("cls");
             CountWord();
             break;
    case 4:  
             system("cls");
             Bmenu(temp);
             break;
    case 5:
            system("cls");
            HeadWord();
            AboutWord();
            printf("按回车键继续·····");
            getchar();
            getchar();
            system("cls");
            break;
}
if(t==6) break;
}while(1);
}

int main()
{
head=(LinkList *)malloc(sizeof(LinkList));
LinkList *temp;
menu(temp);
}
2013-07-01 21:40
快速回复:谁能帮我修改一下(将插入函数修改成替换函数) 求帮助!!
数据加载中...
 
   



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

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