| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 694 人关注过本帖
标题:麻烦帮忙看看有什么问题。。循环跳不出去。。
只看楼主 加入收藏
esc345
Rank: 2
等 级:论坛游民
帖 子:25
专家分:45
注 册:2014-1-27
结帖率:100%
收藏
 问题点数:0 回复次数:8 
麻烦帮忙看看有什么问题。。循环跳不出去。。
#include <stdio.h>
int main(void)
{
    char f[81];
    int a=0;
    char ch;
   
    puts("input the array");
    gets(f);
    puts("put a  char");
    ch=getchar();
   
    while(f[a]!='\0')
    {
        if(f[a]==ch)     
        printf("the first location is %d\n",a);
        a++;
    }
    printf("there is no %s in the array\n",ch);
    return 0;
}
搜索更多相关主题的帖子: include return 
2014-02-04 23:33
kindboy18
Rank: 2
等 级:论坛游民
威 望:1
帖 子:28
专家分:84
注 册:2014-1-24
收藏
得分:0 
没有分不予以解答~
2014-02-05 02:45
fl8962
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:539
专家分:2471
注 册:2012-10-17
收藏
得分:0 
回复 楼主 esc345
#include<iostream>
#include<string>
using namespace std;
int main()
{
   cout<<"pleas input one string"<<endl;
   string a;
   cin>>a;
   int i,j=0;
   char ch;
   cin>>ch;

   for(i=0;a[i]!='\0';++i)
    {
       if(a[i]==ch)
        {cout<<"the location of"<<ch<<"is"<<i<<endl;
          j=1;
        }
    }
   if(j==0)
   cout<<"there is no "<<ch<<" inside"<<endl;
   return 0;
}
Here is the code, hope it will give you some suggestions.

想抽苏烟了。
2014-02-05 03:10
冯天华
Rank: 2
等 级:论坛游民
帖 子:28
专家分:24
注 册:2013-12-14
收藏
得分:0 
这个程序想得到的结果是什么?
2014-02-05 05:41
逆风而前
Rank: 7Rank: 7Rank: 7
来 自:福建
等 级:黑侠
威 望:7
帖 子:193
专家分:567
注 册:2013-2-14
收藏
得分:0 
程序代码:
#include <stdio.h>
#include<string.h>
int main(void)
{
    char f[81];
    int a=0;
    char ch;
    
    puts("input the array");
    gets(f);
//    f[strlen(f)]='\0';
    puts("put a  char");
    ch=getchar();
    
    while(f[a]!='\0')
    {
        if(f[a]==ch)
        {
         printf("the first location is %d\n",a+1);
         break;
        }
        a++;
    }
    if(a==strlen(f))
    {
    printf("there is no %c in the array\n",ch);
    }
    return 0;
}
2014-02-05 09:24
esc345
Rank: 2
等 级:论坛游民
帖 子:25
专家分:45
注 册:2014-1-27
收藏
得分:0 
谢谢各位。。。
2014-02-05 12:43
zuifei07
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2014-2-5
收藏
得分:0 
f最后的字符应该是回车吧。。不是EOF。。。对吧?
2014-02-07 14:11
tianwen0921
Rank: 2
等 级:论坛游民
帖 子:18
专家分:44
注 册:2014-1-27
收藏
得分:0 
程序代码:
while(f[a]!='\0')
    {
        if(f[a]==ch)     
       { printf("the first location is %d\n",a);
         break;
        }
        a++;
    }
2014-02-08 10:07
快速回复:麻烦帮忙看看有什么问题。。循环跳不出去。。
数据加载中...
 
   



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

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