c - 字符串和 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;
}
这是我的代码,我需要找出我给出数字的元素。我将其更改为无效数字,它现在可以完美运行。
解决方案
isdigit
是在 中声明的标准 C 函数<ctype.h>
。您的功能与它冲突。为您的函数选择一个不同的名称。
这将避免有关冲突类型的编译器消息,但您的程序中还有其他错误需要修复。
推荐阅读
- xcodebuild - xcodebuild 忽略 -derivedDataPath
- reactjs - 在 nextjs 中预渲染页面发生错误
- nginx - NGINX SSL handshake error - sslv3 alert certificate expired:SSL alert number 45
- visual-studio - Include compile file (incremental build)
- node.js - How to make a GET request (MongoDB -- Express)?
- mysql - 如何将表名作为参数传递给游标而不以动态方式创建视图
- python - SqlAlchemy:基于货币的金额精度
- vb.net - vb net append list of with item/index list
- ios - 显示 iOS 15 问题的小部件图像。黑色矩形出现/消失在图像上
- ruby-on-rails - 如何在 Rails ActiveRecord 中一次执行多个 JOINS