⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 the.c

📁 与C语言四书五经之《C和指针》的配套的书上源代码。
💻 C
字号:
/*
** Count the number of times the word "the" appears in the standard
** input.  Case is important, and the words in the input are
** separated from each other by one or more white space characters.
*/

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

char	const	whitespace[] = " \n\r\f\t\v";

int
main()
{
	char	buffer[101];
	int	count;

	count = 0;

	/*
	** Read lines until EOF is found.
	*/
	while( gets( buffer ) ){
		char	*word;

		/*
		** Extract words from the buffer one by one
		** until there are no more.
		*/
		for( word = strtok( buffer, whitespace );
		    word != NULL;
		    word = strtok( NULL, whitespace ) ){
			if( strcmp( word, "the" ) == 0 )
				count += 1;
		}
	}

	printf( "%d\n", count );

	return EXIT_SUCCESS;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -