Here is the main.c code/text
#include <stdio.h>
#include <stdlib.h>
#include "conio.h"
int main()
{
gotoxy (10,10);
printf("Hello world!\n");
return 0;
}
Here is the conio.c code/text
#include <termios.h> /* Linux System File */
/*************************************************************************
* Function: gotoxy
* Parameters: column - X, row - Y
* Description: Moves printing position to specified screen/window location
*
* Returns: Nothing
**************************************************************************/
void gotoxy(int x, int y)
{
// This uses what's called an ANSI escape sequence to move the cursor
// to a particular location in the window.
printf("\033[%d;%dH", y, x);
}
/*************************************************************************
* Function: clrscr
* Parameters: none
* Description: Clears the "screen" (console printing area)
*
* Returns: Nothing
**************************************************************************/
void clrscr()
{
// This uses what's called an ANSI escape sequence to clear the
// viewing portion of the terminal window.
printf ("\033c");
}
/*************************************************************************
* Function: getch()
* Parameters: none
* Description: Waits for a single key to be pressed, rather than needing
"Enter" or "Return" to be pressed - hence the jiggery pokery
* Returns: The key code that was pressed.
**************************************************************************/
char getch(void)
{
int c=0;
struct termios org_opts, new_opts;
int res=0;
//----- store old IO settings in a structure -----------
res=tcgetattr(fileno(stdin), &org_opts);
//Keep a copy:
new_opts = org_opts;
//Update the bits we're interested in
new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);
//Put the settings into the system.
tcsetattr(fileno(stdin), TCSANOW, &new_opts);
//Check for a keypress
c=getchar();
//------ restore old settings ---------
res=tcsetattr(fileno(stdin), TCSANOW, &org_opts);
//assert(res==0);
return(c);
}
Here is the conio.h code/text
void gotoxy(int x, int y);void clrscr(void);
char getch(void);
No comments:
Post a Comment