首页 > 学院 > 开发设计 > 正文

统计the的个数

2019-11-11 02:52:18
字体:
来源:转载
供稿:网友
#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;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表