除了使用到這篇 文章 提到的Method外,還會使用到ReadConsolestrcatstrlenmemset

 

可使用於Windows 10的作業系統

 


#include <stdio.h>
#include <string.h>
#include <windows.h>

int main()
{
    HANDLE handle;
    DWORD cnt;
    DWORD mode;
    char input[11] = "";//一個char占用1 byte,一個中文字占用2 bytes,所以input[10]最多一次接收5個中文,最後一個要儲存\0
    char str[80] = "";

    handle = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(handle, &mode);
    SetConsoleMode(handle, mode & ~ENABLE_LINE_INPUT);

    while(ReadConsole(handle, input, 10, &cnt, NULL))//一次最多讀取5個中文,多餘的捨棄
    {
        if(input[0] == 'q')//若使用者輸入q則結束
            break;
        else
        {
            printf("%s", input);//顯示輸入的字串
            strcat(str, input);
            memset(input, 0, sizeof(input));//將input清空
        }
    }
    printf("\n輸入的字串為:%s\n", str);
}


 

arrow
arrow
    全站熱搜

    Yang 發表在 痞客邦 留言(0) 人氣()