| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 464 人关注过本帖
标题:字符串匹配,但是无法输入子串,请问问题出在哪里?
只看楼主 加入收藏
chuanglan
Rank: 2
等 级:论坛游民
威 望:2
帖 子:91
专家分:29
注 册:2012-8-14
结帖率:84.62%
收藏
已结贴  问题点数:20 回复次数:2 
字符串匹配,但是无法输入子串,请问问题出在哪里?
程序代码:
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#define string_size  10000


  int T_len;
  int S_len;

typedef struct LinkSeq
{
   char str[string_size];
   int length;
}Seq;

int intgNum = 0,charNum = 0,blankNum = 0;

void Statistics(Seq Essay)
{
   int j=0;
   while(Essay.str[j]!='\0')
    {   if( ('A'<=Essay.str[j]&&Essay.str[j]<='Z') || ('a'<=Essay.str[j]&&Essay.str[j]<='z'))
         charNum ++;
        else if( '0'<=Essay.str[j]&&Essay.str[j]<='9')
             {
               puts("its a integer!");
               getch();
               intgNum ++;
             }
         else if(Essay.str[j]==' ')
            {
              puts("its a blank space!");
              getch();
              blankNum ++;
            }
        }
}


void GetNext(char T[],int *next)
{
  int i,j;
  i = 1;
  j = 0;
  next[1] = 0;
  while(i < T_len)
    {
        if(j==0 || T[i] == T[j])
          {
             ++i;
             ++j;
             next[i] = j;
          }
        else
          j = next[j];
    }
}

int Index_KMP(char S[],char T[],int pos)
{
    int i = pos;
    int j = 1;
    int next[255];
    GetNext(T,next);
    while(i <= S_len && j <= T_len)
      {
         if(j==0 || S[i] == T[j])
           {
             ++i;
             ++j;
           }
         else
           j = next[j];
      }
   pos = i;
   if(j > T_len)
     return i-T_len;
   else
     return 0;
}
void SubStrFreq(Seq Essay,char T[])
{
  //int times = 0;
  int startLoc;
  startLoc = Index_KMP(Essay.str,T,0);
  printf("we find the substr at %d \n",startLoc);
  //return times;
}
/*
void DelSubStr(Seq Essay)
{
  

}      */

void main()
{
   int i,j,row,N_line;
   Seq Essay;
   char subStr[string_size];
   FILE *fp;
   if( (fp=fopen("A.txt","r")) == NULL)
    {
      puts("Cannot open the file!");
      getch();
      exit(0);
    }
   printf("please input lines of the essay: ");
   scanf("%d",&N_line);
   for(row=1,j=0; row<N_line; row++)
     for(i=0; i<80; i++,j++)
          {
             Essay.str[j] = fgetc(fp);
             putchar(Essay.str[j]);
          }
   Essay.str[j++] = '\0';
   Essay.length = j;  // 记录字符总数
  // printf("\nthe total number of character is %d:\nthe total number of blank space is %d:\nthe total number of  words is %d:\n",charNum,blankNum,Essay.length);
   printf("please input the string you search:");


   gets(subStr);       //这句无法执行



   T_len = strlen(subStr);
   S_len = strlen(Essay.str);
   SubStrFreq(Essay,subStr);
   getch();
   fclose(fp);
}
A.rar (3.82 KB)
搜索更多相关主题的帖子: 10000 字符串 
2013-01-01 14:02
不玩虚的
Rank: 9Rank: 9Rank: 9
来 自:四川
等 级:贵宾
威 望:10
帖 子:331
专家分:1301
注 册:2012-12-9
收藏
得分:14 
好复杂,楼主实现什么功能。能说下不!

同学习......同进步....你帮我......我帮你.....上善若水.....
2013-01-03 02:50
chuanglan
Rank: 2
等 级:论坛游民
威 望:2
帖 子:91
专家分:29
注 册:2012-8-14
收藏
得分:0 
呵呵,这是我们课程设计的题目,谢谢啦
5、 文章编辑(必做)

功能:输入一页文字,程序可以统计出文字、数字、空格的个数。

静态存储一页文章,每行最多不超过80个字符,共N行;

要求(1)分别统计出其中英文字母数和空格数及整篇文章总字数;

(2)统计某一字符串在文章中出现的次数,并输出该次数;

(3)删除某一子串,并将后面的字符前移。

存储结构使用线性表,分别用几个子函数实现相应的功能;

输入数据的形式和范围:可以输入大写、小写的英文字母、任何数字及标点符号。

输出形式:(1)分行输出用户输入的各行字符;

(2)分4行输出"全部字母数"、"数字个数"、"空格个数"、"文章总字数"

(3)输出删除某一字符串后的文章;

现在我的这个程序的代码没有这么多的功能,我现在只是想知道为什么运行的时候不能输入我想要输入的子串

2013-01-03 12:04
快速回复:字符串匹配,但是无法输入子串,请问问题出在哪里?
数据加载中...
 
   



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

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