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

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

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

 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 }

猜你喜欢

转载自www.cnblogs.com/ming-4/p/10532118.html
今日推荐