社区

C语言 帖子详情 c 语言如何判断输入的字符是回车键。 liuliu13654002686 2008-06-03 04:54:10 c 语言如何判断输入的字符是回车键。

...全文

2782 8 打赏 收藏 c 语言如何判断输入的字符是回车键。 c 语言如何判断输入的字符是回车键。 复制链接

扫一扫 分享 举报

写回复 配置赞助广告取 消

确 定

用AI写文章 8 条回复 切换为时间正序 请发表友善的回复… 发表回复 打赏红包 需支付: 0.00 元 取 消 确 定 zjw6861982 2008-06-03 打赏举报 回复 #include "stdio.h"

#define DEBUG

#define DebugPause() printf("call DebugPause()\n")

void main()

{

while(getchar()!='\n')

{

#ifdef DEBUG

DebugPause() ;

#else

printf("NOT CALL DebugPause()\n");

#endif

fflush(stdin);

}

printf("你输入回车了!\n");

} Peter_Cheung 2008-06-03 打赏举报 回复 改了版面, 大家给点意见, 谢谢

http://forum2.kingofcoders.com

hou1104 2008-06-03 打赏举报 回复 [Quote=引用 4 楼 sevenchrist 的回复:]

0x0D

[/Quote]

如果是文本方式打开的话似乎还需要判断一下0A 0D liuliu13654002686 2008-06-03 打赏举报 回复 原体这样的:用条件编译编写一个宏DebugPause()。如果常量DEBUG在程序中定义了,则执行DebugPause()宏暂停程序执行,直至用户按下回车键。如果常量DEBUG没有定义,则不调用DebugPause()宏。

我写的答案这样 但是不是那种效果呢。看看错误在哪里?

/* Note:Your choice is C IDE */

#include "stdio.h"

#define DEBUG

#define DebugPause() printf("call DebugPause()")

void main()

{

char t;

#ifdef DEBUG

{

t=getchar();

printf("%c",t);

while(t!='\n')

{

DebugPause() ;

t=getchar();

printf("%c",t);

}

if(t=='\n') printf("你输入回车了!");

}

#else

printf("NOT CALL DebugPause()");

#endif

} 神出鬼没的七叔 2008-06-03 打赏举报 回复 0x0D johnelf 2008-06-03 打赏举报 回复 [Quote=引用 1 楼 babyvox1999 的回复:]

if(getchar() == '\n')

[/Quote] semi_crazy 2008-06-03 打赏举报 回复 [Quote=引用楼主 liuliu13654002686 的帖子:]

c 语言如何判断输入的字符是回车键。

[/Quote] babyvox1999 2008-06-03 打赏举报 回复 if(getchar() == '\n') 判断字符类型——定义一个变量放置回车键 一些启发 Description 对于给定的字符,判断字符的类型,即字母(alpha)、数字(numeric) 和其它字符(other)。 Input 输入数据包括多组,每组只有一个字符,单独占一行。 Outp /*Description

对于给定的字符,判断字符的类型,即字母(alpha)、数字(numeric)

和其它字符(other)。

Input

输入数据包括多组,每组只有一个字符,单独占一行。

Output

对于每组测试数据,输出判断的结果,每组单独占一行。

Sample Input

A

9

?

Sample Output

alpha

numeric

other*/

#include <... c语言统计字符个数回车字符,C语言统计一串字符中空格键、Tab键、回车键、字母、数字及其他字符的个数(Ctrl+Z终止输入)... 具体代码如下所述:#includevoid main(){int c, letter=0, num=0, blank=0, tab=0, enter=0, other=0 ,i=0, sum=0;printf("Please input a string:\n");while((c=getchar())!=EOF){sum++;if(c==' '){++blank; //空格键的个数}else i... 杭电oj 2017 字符串的统计 #include

int main()

{

int n;

char c,enter;

scanf("%d%c",&n,&enter); //enter 接受回车键

while (n--)

{

int 输入的小挫折 当我们用到循环输入字符时,我们按下的回车键被当作换行键是会被读进去的。

C语言

70,040

社区成员

243,237

社区内容

发帖 与我相关 我的任务 C语言 C语言相关问题讨论 复制链接

扫一扫 分享 确定 社区描述 C语言相关问题讨论 社区管理员

加入社区

获取链接或二维码

近7日

近30日

至今

加载中

查看更多榜单

社区公告

暂无公告 试试用AI创作助手写篇文章吧

+ 用AI写文章