遍历字符串

基本类型 / 字符串

const char *str = "level";

//a string ends with the zero character
for (const char *p = str; *p != '\0'; p++) {
    putchar(*p);
}
putchar('\n');

//strlen walks the whole string: call it once, not in the condition
size_t length = strlen(str);
for (size_t i = 0; i < length; i++) {
    printf("str[%zu] = %c\n", i, str[i]);
}