| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 345 人关注过本帖
标题:【新手求助】关于一个简单程序的core dump问题,求帮助!!
只看楼主 加入收藏
这可怎么办
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-11-1
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
【新手求助】关于一个简单程序的core dump问题,求帮助!!
新手求助~
在网上做一个很简单的OJ,题目大概意思如下:
flymouse is poor in EnGlish but his girlfriend is good at English这句话有两个错误:第一个字母没大写,后面G要小写
  1. Make the initial letter of the first word of the sentence to be capital.
  2. Make the non-initial letters of the non-first words of the sentence to be small.
其实就是一句话首字母要大写,之后的词不管首字母其他要小写。
Flymouse is poor in English but his girlfriend is good at English

Input
The first line contains a single integer t, indicating the number of test cases, followed by one line for each test case. The line for each test case contains a sentence from flymouse's composition. the length of the sentence will be not larger than 10000. For simplicity, punctuations will always be omitted.
Output
There should be one output line per test case containing the correct sentence.
Sample Input
1
flymouse is poor in EnGlish but his girlfriend is good at English

Sample Output
Flymouse is poor in English but his girlfriend is good at English
===========================================================
我的程序代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 int main()
 {
     char s[10002];
     int t,a,b,i,len;
     scanf("%d",&t);
     while(t--)
     {
         memset(s,0,sizeof(s));
         gets(s);
         len=strlen(s);
         if(s[0]>96&&s[0]<123)
         {
             s[0]=s[0]-32;
         }
         a=1;
         while(s[a]!=32)
         {
             a++;
         }
         b=a+1;
         while(s[b]!='32)
         {
             b++;
         }
         for(i=1;i<b;i++)
         {
             if(s[i]>64&&s[i]<91)
             {
                 s[i]=s[i]+32;
             }
         }
         while(a!=len)
         {
            for(i=a+2;i<b;i++)
            {
                if(s[i]>64&&s[i]<91)
                {
                    s[i]=s[i]+32;
                }
            }
            a=b;
            b=a+1;
            while(s[b]!=32'||s[b]!='\0')
            {
                b++;
            }
        }
        puts(s);
    }
    return 0;
}
===========================================================
这个程序在linux上运行每次输入第一个数字T后程序就说segment fault(core dump)
我查了一下core dump的问题,在gdb中显示的是倒数第四行“while(s[b]!=32'||s[b]!='\0')”这句话有问题。。但是我实在看不出来问题,,,走投无路来论坛求助了。。
搜索更多相关主题的帖子: capital English girlfriend 字母 
2012-11-01 09:18
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:20 
你这程序 起步就没看明白
最好注上一些注释

[ 本帖最后由 wp231957 于 2012-11-1 09:32 编辑 ]

DO IT YOURSELF !
2012-11-01 09:30
快速回复:【新手求助】关于一个简单程序的core dump问题,求帮助!!
数据加载中...
 
   



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

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