#include<iostream>
#include<Windows.h>
#include<conio.h>
using namespace std;
void writestring(const char *, short, short, short = 7, short = 0);
void gotoxy(short, short);
int main()
{
writestring("My name is not khan", 20, 10, 4, 1);
_getch();
return 0;
}
void writestring(const char * str, short col, short row, short color, short pnumber)
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); //h is handle of current running program
SetConsoleTextAttribute(h, color); // Text of the screen now have color 4 (RED)
cout << "Page Number : " << pnumber << endl;
while (*str != '\0')
{
gotoxy(col, row);
putchar(*str);
col++;
str++;
}
}
void gotoxy(short col, short row)
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD position = { col, row };
SetConsoleCursorPosition(h, position);
}
Ad
Chapter - 4: Functions
Write a program which contains a writestring() function which displays a string at a given row and column on a given VDU page, in a given color. If the page number and the color are not passed the page number zero and color 7 should be passed.
Ad
Ad