|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
最近在学c语言,想写一个统计字符串中大小写字母的程序,代码如下,但是运行后每次输出的结果都不正确,请高手指点
#include <stdio.h>
main()
{
void letter_count(char *p_,int x,int y);
char string[]={"I am a student,and I am 18 years old!"},*p;
int m,n ;
p = string;
letter_count(p,m,n);
printf("%d %d \n\n",m,n);
}
void letter_count(char *p_,int x,int y)
{
int i;
for(i=0;*(p_+i)!='\0';i++)
{
if(*(p_+i)>64&&*(p_+i)<91)
{
x++;
}
else
{
if(*(p_+i)>96&&*(p_+i)<123)
{
y++;
}
}
}
}
执行后结果是两个错误数字,我想把letter_count(char *p_,int x,int y)函数的x,y值给m,n,能不能这样?如果不可以,可以怎么修改,谢谢大家!
- #include <stdio.h>
- void letter_count(char *p_,int *x,int *y);//用指针传递
- int main()
- {
- char string[]="I am a student,and I am 18 years old!",*p;
- int m=0,n=0 ;
- p = string;
- letter_count(p,&m,&n);
- printf("%d %d \n\n",m,n);
- system("pause");
- return 0;
- }
- void letter_count(char *p_,int *x,int *y)
- {
- int i;
- for(i=0;*(p_+i)!='\0';i++)
- {
- if(*(p_+i)>64 && *(p_+i)<91)
- {
- (*x)++;
- }
- else
- {
- if(*(p_+i)>96 && *(p_+i)<123)
- {
- (*y)++;
- }
- }
- }
- }
复制代码
|
|