首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C WPM程序中检测回车键?

如何在C WPM程序中检测回车键?
EN

Stack Overflow用户
提问于 2016-01-14 12:40:33
回答 1查看 76关注 0票数 1

我应该创建一个打字导师程序,这本质上类似于WPM测试明确的一段。其想法是,程序将在按enter时自动检查结果,无论用户是否已完成整个段落的键入(即:在段落中间结束)。问题是,我如何在不使用getch等蛮力编码的情况下检测enter键或'\n‘?

以下是目前为止的代码:

代码语言:javascript
复制
#include <stdio.h>
#include <string.h>
#include <conio.h>

// Initializer

int x=0, y=0;
int mistake=0;
char entry [200][20];
char paragraph [200][20] = { // paragraph[0][0][0] = paragraph[WORD][LETTER]
/* 1) 92 WORDS, 579 CHARS */ "English", "students", "are", "sometimes", "taught", "that", "a", "paragraph", "should", "have", "a", "topic", "sentence", "or", "main", "idea,", "preferably", "first,", "and", "multiple", "supporting", "or", "detail", "sentences", "which", "explain", "or", "supply", "evidence.", "One", "technique", "of", "this", "type,", "intended", "for", "essay", "writing,", "is", "known", "as", "the", "Schaffer", "paragraph.", "For", "example,", "the", "following", "excerpt", "from", "Dr.", "Samuel", "Johnson's", "Lives", "of", "the", "English", "Poets,", "the", "first", "sentence", "is", "the", "main", "idea:", "that", "Joseph", "Addison", "is", "a", "skilled", "describer", "of", "life", "and", "manners.", "The", "succeeding", "sentences", "are", "details", "that", "support", "and", "explain", "the", "main", "idea", "in", "a", "specific", "way."};
int wordcount = { 92 };

// Interface

printf("Welcome to the Typing Tutor!\n");
printf("===============================================================================\n");
for (x=0;x<wordcount[0];x++) printf ("%s ", paragraph[0][x]);
printf("\n===============================================================================\n");
printf("Please type this paragraph below:\n\n");

// Input / Word Count Incrementer

for (x=0;x<wordcount[0];x++){
    scanf ("%s", &entry[x]);
    if (entry[x] == "\n") break; // Supposedly detects "enter", then breaks the loop. Doesn't seem to work.
    word++;
}

// Typo Checker

for (x=0;x<word;x++) if (strcmp(entry[x],paragraph[0][x]) != 0) mistake++;

// Output

y=wordcount[0]-word;

if (word>0) printf("You did not type %i words.\n", y);
else if (word<0) printf("You overtyped %i words.\n", y);
printf("You have made %i typoes.\n\n", mistake);
EN

回答 1

Stack Overflow用户

发布于 2016-01-14 14:20:59

您可以使用getch()或kbhit()来记录Enter键并将其存储在getch()的variable.Like中。

K=getch()

Kbhit()-It是一个非常好的函数,可以用来查找按下了哪个键

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34781853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档