C语言:将形参s所指字符串中所有ASCII码值小于97的字符存入形参t所指字符数组中,

时间:2023-03-09 20:35:44
C语言:将形参s所指字符串中所有ASCII码值小于97的字符存入形参t所指字符数组中,

//将形参s所指字符串中所有ASCII码值小于97的字符存入形参t所指字符数组中,形成一个新串,并统计出符合条件的字符个数返回。

//关注点:使用*(t+n)的方式可以不改变指针的指向,像数组一样处理指针。

 #include  <stdio.h>
int fun(char *s, char *t)
{ int n=;
while(*s)
{ if(*s < ) {
/**********found**********/
*(t+n)= *s ; n++; }
/**********found**********/
s++ ;
}
*(t+n)=;
/**********found**********/
return n ;
}
void main()
{ char s[],t[]; int n;
printf("\nEnter a string:\n"); gets(s);
n=fun(s,t);
printf("\nThere are %d letter which ASCII code is less than 97: %s\n",n,t);
}