3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

c言語超初心者が適当なコードでカウンターをつくる!

Last updated at Posted at 2022-03-06

こんにちは

いつもはjavascriptでコードを書いてる人が1日c言語を勉強するどうなるのかやってみました
これは、カウンターっていうよりかはただの上キー長押しで数増えたりするだけのものです
そして結局コードはこんな感じ

index.c
#include <stdio.h>
#include <windows.h>
int main(void) {
    int count = 0;
    printf("************************************************\n");
    printf("**キーボードでスペースキーを押したら終了します**\n"); 
    printf("****************上キーでcount→UP****************\n"); 
    printf("***************下キーでcount→DOWN***************\n");
    printf("************************************************\n");
    while(1) {
        if(GetAsyncKeyState(VK_UP) & 0x01 ) {
            count++;
            printf("%d",count);
            printf("\n");
        }else{
            if(GetAsyncKeyState(VK_DOWN) & 0x01 ) {
                count--;
                printf("%d",count);
                printf("\n");
            }else{
                if(GetAsyncKeyState(VK_SPACE) & 0x01 ) {
                    printf("終了します\n");
                    break;
                }
            }
        }
        Sleep(1);
    }
}

実行したらコメントが表示されて上キーと下キーで数をかえれるものです
なんかまだ学びたい気もするのでなにかあったらコメントお願いします

3
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?