아스키코드 179이상의 문자는 윈도우에서 표현할 수 없나요?
글쓴이: bshi02 / 작성시간: 목, 2023/08/31 - 3:18오후
아래의 코드는 미로에 갖힌 생쥐가 우선법으로 탈출하는 코드인데요, 컴파일해서 실행하면 화면에 아스키코드가 깨져서 나오네요.
이게 원래 예전 터보c용 소스라서 그당시 함수중에 delay나 clrscr,bioskey(0),gotoxy처럼 현재 쓰지 않는 것들을 수정했지만 아스키코드표에 나온 179와 그 이상의 아스키 문자는 실행하면 깨져서 나오네요.
현재 윈도우화면에서 179이상의 아스키 문자가 제대로 표시 될 수 있도록 설정하거나 이 소스를 수정해서 아스키 문자 179이상이 제대로 나오도록 할 수 있는 방법은 없을까요?
#include <stdio.h> #include <windows.h> #include <conio.h> #include <stdlib.h> void gotoxy(int x,int y); #define MAZE_SIZE 19 #define ROBOT 2 int maze[MAZE_SIZE][MAZE_SIZE]= {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, {0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1}, {1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1}, {1,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,1}, {1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1}, {1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1}, {1,0,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1,0,1}, {1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1}, {1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1}, {1,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1}, {1,0,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1}, {1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,1,0,1}, {1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,0,1,0,1}, {1,0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1}, {1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1}, {1,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1}, {1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,0,1}, {1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; int sx=MAZE_SIZE-1,sy=MAZE_SIZE-2; int *rec; #define UP 1 #define RIGHT 2 #define DOWN 4 #define LEFT 8 int get_shape(int m[][MAZE_SIZE],int x,int y) { static int shape[]= {32,179,196,192,179,179,218,195,196,217,196,193,191,180,194,197 }; int s=0; if(m[y][x]) { if(y>0&&m[y-1][x])s|=UP; if(y<MAZE_SIZE-2&&m[y+1][x])s|=DOWN; if(x>0&&m[y][x-1])s|=LEFT; if(x<MAZE_SIZE-2&&m[y][x+1])s|=RIGHT; } return shape[s]; } void draw_maze(int m[][MAZE_SIZE]) { int i,j; for(j=0;j<MAZE_SIZE;j++) for(i=0;i<MAZE_SIZE;i++) { gotoxy(i+1,j+1); putch(get_shape(m,i,j)); } } void record(int x,int y) { static int index=0; rec[index++]=x; rec[index++]=y; } void forward(int *x,int *y,int dir) { gotoxy(*x+1,*y+1); putch(' '); *x=(dir==LEFT)?--(*x):(dir==RIGHT)?++(*x):*x; *y=(dir==UP)?--(*y):(dir==DOWN)?++(*y):*y; record(*x,*y); gotoxy(*x+1,*y+1); putch(ROBOT); } void right(int *dir) { *dir<<=1; *dir=(*dir>LEFT)?UP:*dir; } void left(int* dir) { *dir>>=1; *dir=(*dir==0)?LEFT:*dir; } int still_in_maze(int x,int y) { if(x>0&&x<MAZE_SIZE-1&&y>0&&y<MAZE_SIZE-1) return 1; else return 0; } int wall_ahead(int m[][MAZE_SIZE],int x,int y,int dir) { x=(dir==LEFT)?--x:(dir==RIGHT)?++x:x; y=(dir==UP)?--y:(dir==DOWN)?++y:y; return m[y][x]; } void right_hand(int m[][MAZE_SIZE],int x,int y,int dir) { gotoxy(x+1,y+1); putch(ROBOT); record(x,y); forward(&x,&y,dir); while(still_in_maze(x,y)) { _sleep(100); right(&dir); while(wall_ahead(m,x,y,dir)) left(&dir); forward(&x,&y,dir); } record(-1,-1); } void del_path(int i,int j) { while(rec[j]>=0) rec[i++]=rec[j++]; rec[i]=-1; } void shortest_path(void) { int i=0,x,y,j,x1,y1; while(rec[i]>=0) { x=rec[i]; y=rec[i+1]; j=i+2; while(rec[j]>=0) { x1=rec[j]; y1=rec[j+1]; if(x==x1&&y==y1) del_path(i,j); j++; j++; } i++; i++; } i=0; while(rec[i]>=0) { x=rec[i++]; y=rec[i++]; gotoxy(x+1,y+1); putch(ROBOT); _sleep(100); gotoxy(x+1,y+1); putch(' '); } } void main() { rec=(int*)malloc(MAZE_SIZE*MAZE_SIZE); if(rec==NULL) { puts("\r\n Memory allocation error!"); exit(1); } system("cls"); draw_maze(maze); gotoxy(40,5); puts("Simulation of Micro Mouse"); gotoxy(40,10); puts(" Press any key to start...."); kbhit(); right_hand(maze,sx,sy,LEFT); gotoxy(40,10); puts(" Press any key to see shortest path...."); kbhit(); shortest_path(); gotoxy(40,10); puts(" Press any key to end program..."); kbhit(); } void gotoxy(int x,int y) { COORD pos={x,y}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos); }
Forums:
font 관련된 건 아닌가요? encoding 관련은
font 관련된 건 아닌가요? encoding 관련은 없나요?
저도 잘 모르지만 참고하셔요.
세벌 https://sebuls.blogspot.kr/
이 글(https://stackoverflow.com
이 글(https://stackoverflow.com/questions/15528359/printing-utf-8-strings-with-printf-wide-vs-multibyte-string-literals)을 참고해 보세요.
댓글 달기