1. 程式人生 > >用c語言指針處理字符串

用c語言指針處理字符串

image tdi while clas int color result 處理 std

字符串的處理方法有兩種:一種方法是使用字符數組處理字符串,另一種是方法是使用字符指針處理字符串。

後一種也是c語言比較常用的方法。下面我們來看一個列子:

 1 #include<stdio.h>
 2 int main()
 3 {
 4     char a[50],*str1,*str2;
 5     char b[]="I am student.";
 6     str1 = a;
 7     str2 = b;
 8     while((*str1=*str2)!=\0)
 9     {
10         str1++;
11         str2++;
12 } 13 printf("Result:%s\n",b); 14 return 0; 15 }

運行結果:

技術分享

用c語言指針處理字符串