国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
將一個(gè)字符串反轉(zhuǎn)的C程序

http://blog.csdn.net/cogbee/article/details/37559205

2014-07-08 

很久很久沒有寫C程序了,C++已經(jīng)深入骨髓。寫起C來居然還是非常吃力。

比如在C中,數(shù)組和字符串是不能互相賦值的。這可難為了。輸出一個(gè)數(shù)組還要一個(gè)一個(gè)輸出,

下面是一個(gè)下例子,就是將一個(gè)字符串反轉(zhuǎn)。

  1. #include <stdio.h>  
  2. #include <string.h>  
  3. #include <sys/socket.h>  
  4. #include <arpa/inet.h>  
  5. #include <unistd.h>  
  6. #include <netinet/in.h>  
  7. #include <stdlib.h>  
  8.   
  9. #define MAXLINE 1024  
  10. static char revbuf[MAXLINE];  
  11.   
  12. void *reverse(char * buf,int len)  
  13. {  
  14.     int i,n;  
  15.       
  16.     if(len > MAXLINE || len < 0)  
  17.     {  
  18.         printf("length is error\n");  
  19.               
  20.     }  
  21.     i = 0;  
  22.     n = len;  
  23.     while(i < len)  
  24.     {  
  25.         revbuf[i++] = *(buf+(--n));  
  26.     }  
  27.     revbuf[i] = '\n';  
  28.   
  29. }  
  30.   
  31. int main()  
  32. {  
  33.     char *buf = "OK,I am test";  
  34.     reverse(buf,strlen(buf));  
  35.     fwrite(revbuf,1,strlen(buf)+1,stdout);  
  36. }  

在不能數(shù)組跟字符串相互賦值,字符串不能當(dāng)成數(shù)組用的時(shí)候,只能指針一個(gè)一個(gè)指定了。

為什么C中字符串不能當(dāng)數(shù)組使用呢?

在另外一個(gè)地方似乎找到了答案:

In C arrays are non-modifiable lvalues, you can't change what they point to since they don't point anywhere in the first place.

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Redis 數(shù)據(jù)結(jié)構(gòu) 之 SDS
數(shù)組與字符串轉(zhuǎn)換
[redis]SDS和鏈表
Java中String類的concat方法
Java中的String為什么是不可變的?
【Redis底層解析】字符串類型
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服