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

📄 input1.c

📁 C.Game.Programming.For.Dummies.原码
💻 C
字号:
#include <stdio.h>
#include <conio.h>

#define CR 0x0d     //carriage return
#define ESC 0x1b    //Escape key
#define TAB 0x09
#define LF 0x0a     //Line feed
#define BACKSPACE 0x08
#define NULL 0      //Empty character
#define TRUE 1
#define FALSE 0
#define LENGTH 15   //size of the string

void input(char *string, int length);

void main()
{
    char string[LENGTH];

    printf("What is your name?");
    input(string,LENGTH);
    printf("Darn glad to meet you, %s!\n",string);
}

void input(char *string, int length)
{
    int done = FALSE;
    int index = 0;
    char ch;

    string[0] = NULL;   // init the buffer

    do
    {
        ch = getch();

/* Check to see if the buffer is full */

        if (index == length)
        {
            switch(ch)
            {
                case CR:
                    break;
                default:
                    ch = NULL;
                    break;
            }
        }

/* process the keyboard input */

        switch(ch)
        {
            case CR:        //Enter key
                string[index] = NULL;
                done = TRUE;
                break;
            case NULL:
                break;
            default:        //display & sto
                putchar(ch);
                string[index] = ch;
                index++;
                break;
        }
    }
    while(!done);

}

⌨️ 快捷键说明

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