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

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

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

 1 #include  <stdio.h>
 2 int fun(char  *s, char  *t)  3 { int  n=0;  4   while(*s)  5   { if(*s < 97) {  6 /**********found**********/
 7      *(t+n)= *s ;  n++; }  8 /**********found**********/
 9      s++ ; 10  } 11   *(t+n)=0; 12 /**********found**********/
13   return n ; 14 } 15 void main() 16 { char  s[81],t[81];    int n; 17   printf("\nEnter a string:\n"); gets(s); 18   n=fun(s,t); 19   printf("\nThere are %d letter which ASCII code is less than 97: %s\n",n,t); 20 }
相关文章
相关标签/搜索