Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define LINHA 40
- #define COLUNA 71
- #define UP_ARROW 72
- #define DOWN_ARROW 80
- #define LEFT_ARROW 75
- #define RIGHT_ARROW 77
- #define ENTER 13
- #define BACKSPACE 8
- #define MARGEM 10
- int main( )
- {
- initwindow(640, 480, "Editor Beta");
- char x[LINHA][COLUNA];
- int tecla;
- int i , j , linha , coluna ;
- linha = coluna = 0;
- for(i=0;i<LINHA;i++)
- for(j=0; j<COLUNA; j++)
- {
- x[i][j]= 0;
- }
- while(1)
- {
- if(kbhit())
- {
- while((tecla = getch()) != 27)
- {
- switch(tecla)
- {
- case 0:
- tecla=getch();
- switch(tecla)
- {
- case UP_ARROW:
- if(linha>0)
- linha--;
- if( x[linha][coluna] != 0 )
- for( j=0; x[linha][j]!=0;j++ )
- coluna = j;
- break;
- case DOWN_ARROW:
- if(linha<40)
- linha++;
- break;
- case RIGHT_ARROW:
- if(coluna>0)
- coluna++;
- break;
- case LEFT_ARROW:
- if(coluna>0)
- coluna--;
- break;
- }
- break;
- case ENTER:
- linha++;
- coluna=0;
- break;
- case BACKSPACE:
- if (linha == 0 && coluna == 0)
- break;
- else if (linha > 0 && coluna == 0){
- linha--;
- for(j=0;x[linha][j]!=0;j++)
- coluna=j+1;
- }
- if(coluna==0)
- x[linha][coluna]=0;
- else
- x[linha][--coluna]=0;
- swapbuffers();
- cleardevice();
- setcolor(WHITE);
- for(i=0 ; i<=linha ; i++){
- outtextxy(MARGEM, MARGEM+i*20 , x[i]);
- printf("Cursor:%d %d\n", linha , coluna);
- }
- break;
- default:
- x[linha][coluna++] = (char) tecla;
- swapbuffers();
- cleardevice();
- setcolor(WHITE);
- for(i=0 ; i<=linha ; i++){
- outtextxy(MARGEM, MARGEM+i*20 , x[i]);
- printf("Cursor:%d %d\n", linha , coluna);
- }
- break;
- }
- swapbuffers();
- cleardevice();
- setcolor(WHITE);
- // outtextxy(MARGEM, MARGEM+linha , x[linha]);
- for(i=0 ; i<=linha ; i++){
- outtextxy(MARGEM, MARGEM+i*20 , x[i]);
- printf("Cursor:%d %d\n", linha , coluna);
- }
- }
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement