| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1536 人关注过本帖
标题:请过路的人帮我修改下关于指针的程序
只看楼主 加入收藏
pl123586
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2016-10-13
结帖率:0
收藏
 问题点数:0 回复次数:2 
请过路的人帮我修改下关于指针的程序
#include <stdio.h>
#include <stdlib.h>
#define len 80
int main(){
    char string[len],*pstr;
    int t=0;
   
    pstr=string;
    printf("Input a string:");
    gets(pstr);
      
    while(*pstr++!='\0')
      if(*pstr==' '){
          t++;
          continue;
          printf("%d",t);}
      else
       printf("\n");
     
    if(*pstr=='\0')
      printf("NO space in '%s'.\n,string");
    system("PAUSE");
    return 0;
}
我不知道错在哪,如果可以请帮我指出
题目:用指针方法实现:字符串指针示例:输入一串字符,检测输入的字符串中是否有空格,计算其中空格的个数。
搜索更多相关主题的帖子: continue include system return 字符串 
2016-12-22 14:26
groveer
Rank: 3Rank: 3
来 自:世界的一角
等 级:论坛游侠
威 望:1
帖 子:77
专家分:182
注 册:2013-11-18
收藏
得分:0 
continue会结束本次循环,应把printf放在它前面,后面还有个小问题一并帮你改了
程序代码:
#include <stdio.h>
#include <stdlib.h>
#define len 80
int main(){
    char string[len],*pstr;
    int t=0;
    
    pstr=string;
    printf("Input a string:");
    gets(pstr);
       
    while(*pstr++!='\0')
      if(*pstr==' '){
          t++;
          printf("%d",t);
          continue;
          }
      else
       printf("\n");
     
    if(*pstr=='\0')
      printf("NO space in '%s'.\n",string);
    system("PAUSE");
    return 0;
}

付出不亚于任何人的努力~
2016-12-22 15:03
musicwyr
Rank: 2
等 级:论坛游民
帖 子:3
专家分:14
注 册:2016-12-16
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#define len 80
int main()
{
    char string[len];
    char *pstr;
    int t=0;
    printf("Input a string:");
    gets(string);
    pstr = string;

    while(*pstr++!='\0')
    {
         if(*pstr==' ')
         {
              t++;
              continue;
          }
    }

    printf("space is %d",t);

    system("PAUSE");
    return 0;
}
2016-12-22 15:22
快速回复:请过路的人帮我修改下关于指针的程序
数据加载中...
 
   



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

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