鱼C论坛

 找回密码
 立即注册
查看: 2120|回复: 2

[已解决]C语言

[复制链接]
发表于 2021-1-22 19:23:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include <bits/stdc++.h>
using namespace std;
main()
{
        int i=0;
        char c;
        while(1)
        {
                c='\0';
                while(c!=13&&c!=27)
                {
                        c=getch();
                        printf("%c\n",c);
                }
                if(c==27)
                        break;
                i++;
                printf("The No. is%d\n",i);
        }
        printf("The end");
}
为什么getch()会报错,我看着视频打的
最佳答案
2021-1-22 20:43:52
  1. #include <stdio.h>
  2. #include <conio.h>       // 使用 getch() 、putch() 必须包含此头文件

  3. int main(void)
  4. {
  5.         int i = 0                       ;
  6.         char c                          ;
  7.         c = getch() ;
  8.         while(c != 13 && c != 27) {
  9.                 putch(c)                ;
  10.                 i ++                    ;
  11.                 c = getch()             ;
  12.         }
  13.         putch('\n')                     ;
  14.         printf("The No. is : %d\n" , i) ;        
  15.         printf("The end")               ;
  16. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-22 20:43:52 | 显示全部楼层    本楼为最佳答案   
  1. #include <stdio.h>
  2. #include <conio.h>       // 使用 getch() 、putch() 必须包含此头文件

  3. int main(void)
  4. {
  5.         int i = 0                       ;
  6.         char c                          ;
  7.         c = getch() ;
  8.         while(c != 13 && c != 27) {
  9.                 putch(c)                ;
  10.                 i ++                    ;
  11.                 c = getch()             ;
  12.         }
  13.         putch('\n')                     ;
  14.         printf("The No. is : %d\n" , i) ;        
  15.         printf("The end")               ;
  16. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-1-23 17:33:10 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 13:29

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表