#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXWORD 100
int main()
{
char word[MAXWORD] ;
char* p = NULL;
char result ;
while((result = getword(word,MAXWORD))!=EOF)
{
p = word ;
if(isalpha(result))
for(;*p!='\0';p++)
printf("%c\n",*p);
}
return 0;
}
int getword(char* a , int Max)
{
int getch(void);
void ungetch(int);
char* p = a ;
Max = MAXWORD ;
char c ;
while(isspace(c = getch()))
;
if(c!=EOF)
*p++=c;
if(!isalpha(c))
{
*p = '\0';
return c ;
}
for(; --Max > 0 ; p++)
{
if(!isalnum(*p = getch()))
{
ungetch(*p);
break ;
}
}
*p = '\0';
return a[0] ;
}
输入文本中统计C语言关键字个数之getword()函数——getch()版本
最新推荐文章于 2021-06-22 17:16:03 发布
本文介绍如何使用getword()函数,基于getch()版本,来统计用户输入文本中的C语言关键字。通过示例展示当用户输入特定字符串时,程序如何输出相应的统计结果。
摘要由CSDN通过智能技术生成