Javadream

          A long way and a dream.

          strlen(char *s)

          Posted on 2006-07-19 21:39 oxl 閱讀(302) 評論(0)  編輯  收藏 所屬分類: 技術(shù)感語

          返回字符串不包括"\0"的長度。

          下面是解釋:

          NAME
          ?????? strlen - calculate the length of a string

          SYNOPSIS
          ?????? #include <string.h>

          ?????? size_t strlen(const char *s);

          DESCRIPTION
          ?????? The? strlen()? function? calculates? the? length? of? the string s, not
          ?????? including the terminating `\0' character.



          在unix中,讀入一行時都會在后面加入"\n"緊跟一個"\0",所以strlen往往得不到正確的答案。應該是strlen(s) - 1

          所以清除換行符的方法是
          char test[MAX_LINE];
          //....read from stdin
          test[strlen(test) - 1] = '\0';

          主站蜘蛛池模板: 秀山| 那曲县| 江孜县| 澄迈县| 正阳县| 山西省| 城固县| 朝阳县| 平顶山市| 肥乡县| 宜都市| 南江县| 陵水| 宁蒗| 淳安县| 星子县| 延津县| 德昌县| 临潭县| 连山| 华宁县| 四川省| 昌乐县| 嵊州市| 阳高县| 离岛区| 修武县| 乌海市| 荣昌县| 双城市| 德阳市| 冀州市| 洪湖市| 长武县| 青冈县| 德州市| 阿瓦提县| 上杭县| 余姚市| 开封县| 通山县|