标题:菜鸟请高手帮忙改个程序!
只看楼主
windy_qt
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-9-6
结帖率:100%
已结贴  问题点数:20 回复次数:2 
菜鸟请高手帮忙改个程序!
请大家帮忙看看这个程序,总是运行出错,谢谢大家!
程序代码:
#include<stdio.h>
#include<stdlib.h>
int main()
{
    char str[]="At the first God made the heaven and the earth:"
               "And the earth was waste and without form;"
               "and it was dark on the face of the deep:"
               "and the Spirit of God was moving on the face of the waters."
    char find[10];
    int i,j,find_len=0,count=0;
    int index_num;
    printf("————————————————————");
    printf("%s\n",str);
   
    printf("请输入要搜索的字符串:");
    scanf("%s",find);
   
    while(find[find_len]!='\0')
    {
                               find_len++;
                               }
   
    for(i=0;str[i]!='\0';i++)
    {
                             if(str[i]==(find[0]))
                             {
                                                  for(j=0;j<=find_len;j++)
                                                  {
                                                                         
                                                              if(str[i+j]==find[j])
                                                                  continue;
                                                              else
                                                                  break;
                                                                  }
                                                  if(j==find_len)
                                                  {
                                                                 printf("在%d位置搜索到字符串\n",i);
                                                                 count++;
                                                                }
                               }                                 
    }
    printf("共有%d个符合的字符串\n",count);
   
    system("pause");
    return 0;
}                                                            
                                                     
    
                                                               
   

搜索更多相关主题的帖子: moving heaven without include earth 
2009-09-06 21:25
UserYuH
Rank: 12Rank: 12Rank: 12
来 自:毅华
等 级:火箭侠
威 望:8
帖 子:720
专家分:3300
注 册:2009-8-10
得分:20 
char str[]="At the first God made the heaven and the earth:"
               "And the earth was waste and without form;"
               "and it was dark on the face of the deep:"
               "and the Spirit of God was moving on the face of the waters."
数组这样赋值不对,不用换行,直接打完,最后要加个';'分号,
·
for(j=0;j<=find_len;j++)  /* 这最后一个循环j<=fing_len,多对比了一次, 改小等于j<fing_len */
   {                                                               
     if(str[i+j]==find[j])
        continue;
     else
         break;
    }
if(j==find_len) /*  */
    {
        printf("在%d位置搜索到字符串\n",i);
            count++;
     }

努力—前进—变老—退休—入土
2009-09-06 21:52
windy_qt
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-9-6
得分:0 
编译正确,谢谢UserYuH!
2009-09-06 22:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-284996-1-1.html




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

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