Code bảng mã ASCII

Image Hosted by ImageShack.us

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
void gotoxy(int x, int y)   // xay dung ham gotoxy
{
  static HANDLE h = NULL;
  if(!h)
    h = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD c = { x, y };
  SetConsoleCursorPosition(h,c);
}

void SetColor(WORD color)
{
    HANDLE hConsoleOutput;
    hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
    GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);

    WORD wAttributes = screen_buffer_info.wAttributes;
    color &= 0x000f;
    wAttributes &= 0xfff0;
    wAttributes |= color;

    SetConsoleTextAttribute(hConsoleOutput, wAttributes);
}

int main(){
    int a[256] = {0};
    a[7] = a[8] = a[9] = a[10] = a[13] = 1;
    char *s = "ASCII table upload by To Son Nguyen";
    gotoxy(40 - strlen(s)/2, 1);
    printf("%s\n\n", s);
    system("color 03"); // Dat mau, mau nen la 1, mau chu la A
    for (int i=0; i<20; i++){
        for (int j=i, k = 0; k<13 && j<256; k++, j += 20){
            SetColor(3);
            printf("%4d ", j);
            SetColor(15);
            if (a[j])
                printf(" ");
            else
                printf("%c", j);
        }

        printf("\n");
    }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: