outtext() and outtextxy() Functions in C Graphics - Syntax and Examples

Introduction to outtext() and outtextxy() Functions

In C graphics programming, the outtext() and outtextxy() functions are used to display text on the graphics screen. These functions are available in the traditional BGI (Borland Graphics Interface) graphics library through the graphics.h header file.

The outtext() function displays text at the current graphics position, whereas the outtextxy() function displays text at a specified X and Y coordinate.

सी ग्राफिक्स प्रोग्रामिंग में outtext() और outtextxy() फंक्शन का उपयोग ग्राफिक्स स्क्रीन पर टेक्स्ट प्रदर्शित करने के लिए किया जाता है। ये फंक्शन पारंपरिक BGI (Borland Graphics Interface) ग्राफिक्स लाइब्रेरी में graphics.h हेडर फाइल के माध्यम से उपलब्ध होते हैं।

outtext() फंक्शन वर्तमान ग्राफिक्स पोजीशन पर टेक्स्ट प्रदर्शित करता है, जबकि outtextxy() फंक्शन निर्धारित X और Y कोऑर्डिनेट पर टेक्स्ट प्रदर्शित करता है।

1. outtext() Function in C Graphics

The outtext() function is used to display a text string at the current graphics position. It accepts a string as an argument.

outtext() फंक्शन का उपयोग वर्तमान ग्राफिक्स पोजीशन पर टेक्स्ट स्ट्रिंग प्रदर्शित करने के लिए किया जाता है। इसमें एक स्ट्रिंग आर्गुमेंट के रूप में दिया जाता है।

Syntax of outtext()

void outtext(char *textstring);

Parameter:

  • textstring: The string that we want to display on the graphics screen.

पैरामीटर:

  • textstring: वह टेक्स्ट स्ट्रिंग जिसे ग्राफिक्स स्क्रीन पर प्रदर्शित करना होता है।

Example of outtext() Function

#include <graphics.h>
#include <conio.h>
int main(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
moveto(100, 100);
outtext("Welcome to C Graphics");
getch();
closegraph();
return 0;
}

Output:

The graphics window displays:

Welcome to C Graphics

Explanation:

The moveto(100, 100) function sets the current graphics position to X = 100 and Y = 100. The outtext() function then displays the given text at that position.

moveto(100, 100) फंक्शन वर्तमान ग्राफिक्स पोजीशन को X = 100 और Y = 100 पर सेट करता है। इसके बाद outtext() फंक्शन दिए गए टेक्स्ट को उसी पोजीशन पर प्रदर्शित करता है।

2. outtextxy() Function in C Graphics

The outtextxy() function is used to display a text string at a specified position on the graphics screen. It accepts three arguments: X-coordinate, Y-coordinate and text string.

outtextxy() फंक्शन का उपयोग ग्राफिक्स स्क्रीन पर किसी निर्धारित पोजीशन पर टेक्स्ट स्ट्रिंग प्रदर्शित करने के लिए किया जाता है। इसमें तीन आर्गुमेंट दिए जाते हैं: X-coordinate, Y-coordinate और टेक्स्ट स्ट्रिंग।

Syntax of outtextxy()

void outtextxy(int x, int y, char *textstring);

Parameters:

  • x: Specifies the horizontal position of the text.

  • y: Specifies the vertical position of the text.

  • textstring: Specifies the text to be displayed.

पैरामीटर्स:

  • x: टेक्स्ट की क्षैतिज पोजीशन निर्धारित करता है।

  • y: टेक्स्ट की ऊर्ध्वाधर पोजीशन निर्धारित करता है।

  • textstring: प्रदर्शित किए जाने वाले टेक्स्ट को निर्धारित करता है।

Example of outtextxy() Function

#include <graphics.h>
#include <conio.h>
int main(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
settextstyle(DEFAULT_FONT, HORIZ_DIR, 2);
outtextxy(100, 100, "Welcome to C Graphics");
outtextxy(100, 150, "Using outtextxy() Function");
getch();
closegraph();
return 0;
}

Output:

The graphics window displays two text strings:

  • Welcome to C Graphics

  • Using outtextxy() Function

Explanation:

In the above program, the first text string is displayed at coordinates (100, 100), and the second text string is displayed at coordinates (100, 150).

उपरोक्त प्रोग्राम में पहली टेक्स्ट स्ट्रिंग (100, 100) कोऑर्डिनेट पर तथा दूसरी टेक्स्ट स्ट्रिंग (100, 150) कोऑर्डिनेट पर प्रदर्शित होती है।

Difference Between outtext() and outtextxy()

outtext()outtextxy()
Displays text at the current graphics position.Displays text at a specified X and Y position.
Accepts one argument.Accepts three arguments.
Syntax: outtext("Hello");Syntax: outtextxy(100, 100, "Hello");
Often used with moveto() to set the text position.Coordinates are supplied directly.

outtext()
outtextxy()
वर्तमान ग्राफिक्स पोजीशन पर टेक्स्ट प्रदर्शित करता है।निर्धारित X और Y पोजीशन पर टेक्स्ट प्रदर्शित करता है।
इसमें एक आर्गुमेंट दिया जाता है।इसमें तीन आर्गुमेंट दिए जाते हैं।
moveto() के साथ उपयोग किया जा सकता है।इसमें कोऑर्डिनेट सीधे दिए जाते हैं।

Important Points

  1. Both functions are used to display text in a BGI graphics window.

    दोनों फंक्शन का उपयोग BGI ग्राफिक्स विंडो में टेक्स्ट प्रदर्शित करने के लिए किया जाता है।

  2. The settextstyle() function can be used to change the font, direction and character size before displaying text.

    टेक्स्ट प्रदर्शित करने से पहले फॉन्ट, दिशा और अक्षरों का आकार बदलने के लिए settextstyle() फंक्शन का उपयोग किया जा सकता है।

  3. The setcolor() function can be used to change the text color.

    टेक्स्ट का रंग बदलने के लिए setcolor() फंक्शन का उपयोग किया जा सकता है।

  4. The moveto() function changes the current graphics position used by outtext().

    moveto() फंक्शन outtext() द्वारा उपयोग की जाने वाली वर्तमान ग्राफिक्स पोजीशन को बदलता है।

  5. Both functions belong to the traditional BGI graphics library and are not standard C functions.

    दोनों फंक्शन पारंपरिक BGI ग्राफिक्स लाइब्रेरी का हिस्सा हैं और Standard C के फंक्शन नहीं हैं।

Note for Modern C Compilers

The above programs are designed for the traditional Turbo C/BGI graphics environment. The graphics.h library and functions such as outtext(), outtextxy() and moveto() are not available by default in modern C compilers such as GCC.

ऊपर दिए गए प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए बनाए गए हैं। graphics.h लाइब्रेरी तथा outtext(), outtextxy() और moveto() जैसे फंक्शन GCC जैसे आधुनिक C कंपाइलर में डिफॉल्ट रूप से उपलब्ध नहीं होते हैं।

Comments

Popular posts from this blog

Complete C Programming Language Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025

C Programming for Finance: A Powerful Tool for Financial Modeling and Analysis