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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM