当前位置: C语言 -- 标准库 -- <string.h> -- size_t

size_t类型


描述:

该类型是表示sizeof运算符运算结果的无符号整数类型。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
/*类型size_t范例*/

#include <stdio.h>
#include <string.h>

int main(void)
{
    const char str[] = "All for one, one for all.";
    const char subStr[] = "aeiouAEIOU";
    const char *ptr = str;
    size_t count = 0;
    size_t length;

    /*统计元音字母出现的次数。*/
    while(*ptr != '\0')
    {
        length = strspn(ptr, subStr);
        if(length == 0)
            ++ptr;
        else
        {
            count += length;
            ptr += length;
        }
    }
    printf("Total %zu vowel%s.\n", count, (count>1)?"s":"");

    return 0;
}


输出:

Total 8 vowels.