鱼C论坛

 找回密码
 立即注册
查看: 1576|回复: 3

是编译器的问题? 还是我函数的问题?

[复制链接]
发表于 2021-11-18 17:37:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我这个程序可以编译,但是运行之后无法输入,
如果不加others的那个函数就没问题,我想请教一下为什么会这样?应该如何解决?

/*********************
编写一个用来统计输入的各个数字,空白符(空格、制表符、换行符)以及所有其他字符出现
次数的程序,分别存放在变量num[10],blank,others里面并打印出来。
**********************/

#include<stdio.h>
#include<conio.h>

int main(void)
{
    int blank1(int blank);
    int blank=0;
    int blank2;

        int others1(int others);
    int others=0;
        int others2;

        others2=others1(others);
    blank2=blank1(blank);

        printf("空白符有%d个.\n",blank2);
        printf("其余字符有%d个.\n",others2);
       
        printf("\n\n");
//        system("pause");
        return 0;
}

int blank1(int blank)      //负责空格符的函数
{
        int blank3=0;
        int c;
       
        while((c=getchar())!=EOF)                                       
        {
                if(c==' ' || c=='\t' || c=='\n')  
                        blank3++;
        }
        return blank3;
}

int others1(int others)   //负责其他字符的函数
{
    int others3=0;
        int c;

        while((c=getch())!=EOF)
        {
            if(c>=33 && c<=47 || c>=58 && c<=126)
                {
                  others3++;
                }
        }
        return others3;
}

/*
int main(void)
{
    int num[10]={0};
    int i,c;
        while((c=getchar())!=EOF)
        {
            if(c>='0'&&c<='9')
                {
                   i=c-'0';
                   num[i]++;
                }
        }
        for(i=0;i<10;i++)
        {
          printf("数字%d有%d个.\n",i,num[i]);
        }

    printf("\n\n");
        return 0;
}
*/
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-11-18 18:09:56 | 显示全部楼层
问题更新一下,修改完代码之后输入的字符出来了,
但是blank函数不起作用了。
代码如下:
/*********************
编写一个用来统计输入的各个数字,空白符(空格、制表符、换行符)以及所有其他字符出现
次数的程序,分别存放在变量num[10],blank,others里面并打印出来。
**********************/

#include<stdio.h>
#include<conio.h>

int main(void)
{
    int blank1(int blank);
    int blank=0;
    int blank2;

        int others1(int others);
    int others=0;
        int others2;

        others2=others1(others);
    blank2=blank1(blank);

        printf("空白符有%d个.\n",blank2);
        printf("其余字符有%d个.\n",others2);
        
        printf("\n\n");
//        system("pause");
        return 0;
}
 
int blank1(int blank)      //负责空格符的函数
{
        int blank3=0;
        int c;
        
        while((c=getchar())!=EOF)                                       
        {
                if(c==' ' || c=='\t' || c=='\n')  
                        blank3++;
        }
        return blank3;
}

int others1(int others)   //负责其他字符的函数
{
    int others3=0;
        int c;

        while((c=getchar())!=EOF)
        {
            if(c>=33 && c<=47 || c>=58 && c<=126)
                {
                  others3++;
                }
        }
        return others3;
}

/*
int main(void)
{
    int num[10]={0};
    int i,c;
        while((c=getchar())!=EOF) 
        {
            if(c>='0'&&c<='9')
                {
                   i=c-'0';
                   num[i]++;
                }
        }
        for(i=0;i<10;i++)
        {
          printf("数字%d有%d个.\n",i,num[i]);
        }

    printf("\n\n");
        return 0;
}
*/
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-11-18 17:38:28 | 显示全部楼层
/*********************
编写一个用来统计输入的各个数字,空白符(空格、制表符、换行符)以及所有其他字符出现
次数的程序,分别存放在变量num[10],blank,others里面并打印出来。
**********************/

#include<stdio.h>
#include<conio.h>

int main(void)
{
    int blank1(int blank);
    int blank=0;
    int blank2;

        int others1(int others);
    int others=0;
        int others2;

        others2=others1(others);
    blank2=blank1(blank);

        printf("空白符有%d个.\n",blank2);
        printf("其余字符有%d个.\n",others2);
        
        printf("\n\n");
//        system("pause");
        return 0;
}
 
int blank1(int blank)      //负责空格符的函数
{
        int blank3=0;
        int c;
        
        while((c=getchar())!=EOF)                                       
        {
                if(c==' ' || c=='\t' || c=='\n')  
                        blank3++;
        }
        return blank3;
}

int others1(int others)   //负责其他字符的函数
{
    int others3=0;
        int c;

        while((c=getch())!=EOF)
        {
            if(c>=33 && c<=47 || c>=58 && c<=126)
                {
                  others3++;
                }
        }
        return others3;
}

/*
int main(void)
{
    int num[10]={0};
    int i,c;
        while((c=getchar())!=EOF) 
        {
            if(c>='0'&&c<='9')
                {
                   i=c-'0';
                   num[i]++;
                }
        }
        for(i=0;i<10;i++)
        {
          printf("数字%d有%d个.\n",i,num[i]);
        }

    printf("\n\n");
        return 0;
}
*/
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-11-18 18:04:39 | 显示全部楼层
我自己找出来了  48行的函数用错了
应该用getchar()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-29 16:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表