| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 378 人关注过本帖
标题:菜鸟请高手帮忙改个程序!
只看楼主 加入收藏
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
快速回复:菜鸟请高手帮忙改个程序!
数据加载中...
 
   



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

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