linux c之遍历字符串数组
生活随笔
收集整理的這篇文章主要介紹了
linux c之遍历字符串数组
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1?問題
比如我們要遍歷字符串數組,我們的思路一般是先求字符串數組的長度,然后再用for循環便利,其實沒必要這樣,我們直接在
字符串數組后面加上個NULL就行再去遍歷
?
?
?
?
?
?
?
?
2?代碼實現
#include <stdio.h>int main() {static const char *data[] = {"chen", "yu", "hello", "word", NULL};for (int i = 0; data[i]; ++i){printf("data is %s\n", data[i]);}return 0; }?
?
?
?
?
?
3?運行結果
data is chen data is yu data is hello data is word?
?
總結
以上是生活随笔為你收集整理的linux c之遍历字符串数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WireShark抓包之提示Alert
- 下一篇: 剑指offer之找到链表里面包含环的入口