Javadream

          A long way and a dream.

          strlen(char *s)

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

          返回字符串不包括"\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';

          主站蜘蛛池模板: 德庆县| 财经| 木兰县| 叶城县| 开阳县| 高雄市| 小金县| 辽阳县| 平顶山市| 吴川市| 昂仁县| 南川市| 镇康县| 新蔡县| 华安县| 靖江市| 樟树市| 上杭县| 繁峙县| 西藏| 钟祥市| 汨罗市| 佳木斯市| 滦南县| 永川市| 平乡县| 武冈市| 外汇| 孟津县| 天祝| 丹阳市| 新安县| 九寨沟县| 贵南县| 呼和浩特市| 中方县| 防城港市| 彭州市| 石渠县| 孝昌县| 潼关县|