统计the的个数

来源:互联网 发布:linux多核cpu工作原理 编辑:程序博客网 时间:2024/06/06 00:59
#include <stdio.h>#include <string.h>//strtok函数声明在此头文件中#include <stdlib.h>char const whitespace[] = " ";//以空格来隔开int main(){char buffer[101];int count = 0;//gets(buffer);//vs2015不支持该函数gets_s(buffer,30);//C11标准定义的新的函数,其中第二参数就是允许的输入长度,会自动添加'\0',输入的字符长度加上'\0'后不能超过该参数的数值char *word;for (word = strtok(buffer, whitespace);word != NULL;word = strtok(NULL, whitespace))//char *strtok(char s[], const char *delim);参数s指向欲分割的字符串,参数delim则为分隔符字符(串)//在第一次调用时,strtok()必须给予参数s字符串,往后的调用则将参数s设置成NULL。每次调用成功则返回指向被分割出片段的指针{if (strcmp(word, "the") == 0)count += 1;}printf("%d\n", count);return 0;}

0 0
原创粉丝点击