以下程式印出 s 的長度
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[] = "You may go farther and fare worse.";
printf("%d\n", strlen(s));
return 0;
}
/* 《程式語言教學誌》的範例程式
http://pydoing.blogspot.com/
檔名:cstrlen.c
功能:示範 string.h 中函數 strlen() 的使用
作者:張凱慶
時間:西元2010年6月 */編譯後執行,結果如下

您可以繼續參考
字串處理 string.h
- char *strcpy(char *s1, const char *s2);
- char *strncpy(char *s1, const char *s2, size_t n);
- char *strcat(char *s1, const char *s2);
- char *strncat(char *s1, const char *s2, size_t);
- int strcmp(const char *s1, const char *s2);
- int strncmp(const char *s1, const char *s2, size_t n);
- char *strchr(const char *s, int c);
- size_t strcspn(const char *s1, const char *s2);
- size_t strspn(const char *s1, const char *s2);
- char *strpbrk(const char *s1, const char *s2);
- char *strrchr(const char *s, int c);
- char *strstr(const char *s1, const char *s2);
- char *strtok(char *s1, const char *s2);
- size_t strlen(const char *s);
- void *memcpy(void *s1, const void *s2, size_t n);
- void *memmove(void *s1, const void *s2, size_t n);
- int memcmp(const void *s1, const void *s2, size_t n);
- void *memchr(const void *s, int c, size_t n);
- void *memset(void *s, int c, size_t n);
2 則留言:
文章第一行是不是打錯字了?
應該是 strlen() 而不是 strtok() 哦
XD
這邊打錯字了,已修改,感謝指正 ^_^
張貼留言