首页 > 解决方案 > 字符串和 isdigit 函数

问题描述

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int digit(s1);
int main()
{char s1[10];
printf("\n Type anything you want:\n");
gets(s1);
printf("The number of digits is:%d",digit(s1));
return 0;
}
int digit(char* s1)
{
    int i=0;
  while(*s1)
{
i+= !!isdigit(*s1++);
}
return i;
}

这是我的代码,我需要找出我给出数字的元素。我将其更改为无效数字,它现在可以完美运行。

标签: cstringprintf

解决方案


isdigit是在 中声明的标准 C 函数<ctype.h>。您的功能与它冲突。为您的函数选择一个不同的名称。

这将避免有关冲突类型的编译器消息,但您的程序中还有其他错误需要修复。


推荐阅读