引言:
这里只是给出了一个利用函数调用以及指针的知识做了一个最普遍的例子,也都是因为有人问我才打出来的。啊哈哈哈哈哈哈,也许以后会勤加更新。
因为是一个很简单的小例子所以废话不多说咱就是说,直接上代码:
#include<stdio.h>
#include<assert.h>//断言引用
void my_strlen(char* str, int* x,int* y)
{
assert(str != NULL);//断言避免出错
while (*str!='\0')
{
if (*str >= 48 && *str <= 57)//ASCII码中1~9的对应
{
(*x)++;//数字加一
}
else
(*y)++;//数字加一
str++;//数组指针加一往后指
}
}
int main()
{
int s_count=0;
int count=0;
int* x = &s_count;
int* y = &count;
char str1[40] = "a2d3d4f2s5dd56h89";
char* strp = str1;
my_strlen(strp,x,y);
printf("数字有%d个\n", s_count);
printf("字母有%d个\n", count);
return 0;
}