An warware: yadda ake amfani da gooxy a cikin harshen c

Tabbas, zan bi jagororin ku a hankali. Mu fara!

Harshen C ya kasance ginshiฦ™i a duniyar shirye-shirye shekaru da yawa. Daga cikin fa'idodinsa da yawa, wanda sau da yawa yakan tabbatar da amfani shine aikin 'gotoxy' a cikin C. Wannan aikin, wanda ke cikin ษ—akin karatu na `conio.h`, yana aiki da farko don sarrafa wurin siginan allo na fitarwa. A zahiri, tare da 'gotoxy', masu haษ“aka C na iya tantance inda za a buga fitarwa ta gaba akan allon wasan bidiyo kai tsaye.

Yin amfani da aikin 'gotoxy' a cikin C na iya haษ“aka ฦ™a'idodin gani da tsari na abubuwan wasan bidiyo, kuma yana da fa'ida musamman yayin gina shirye-shirye kamar wasanni, inda sanya abu akan allon wasan bidiyo yana taka muhimmiyar rawa.

Fahimtar aikin 'gotoxy' a cikin C

Aikin 'gotoxy' yana ba mu damar sake saita siginan kwamfuta akan allon wasan bidiyo, amma yana buฦ™atar a lura cewa ana amfani da wannan galibi a cikin yanayin DOS kuma baya samun amfani a dandamali na Windows ko Linux na zamani.

#include <conio.h>

void main()
{
    clrscr();
    gotoxy(10, 20);
    printf("Hello, World!");
    getch();
}

A cikin wannan snippet lambar, aikin 'gotoxy' yana mayar da siginan kwamfuta zuwa matsayin da (10, 20) ke nunawa akan allon wasan bidiyo. Aikin 'printf' sannan ya buga kirtani "Sannu, Duniya!" farawa daga inda aka saita ta aikin 'gotoxy'.

  • Ana amfani da aikin 'clrscr()' don share allon wasan bidiyo kafin mu aiwatar da aikin 'gotoxy'.
  • Ana amfani da aikin `getch()` don jira mai amfani ya danna maษ“alli kafin shirin ya ฦ™are.

Yin aiki 'gotoxy' daidai a cikin Muhalli na zamani

Kamar yadda muka lura, `gotoxy` yana daure da tsohuwar muhallin DOS kuma maiyuwa baya aiki da kyau a tsarin yanzu. Koyaya, babu buฦ™atar damuwa saboda muna iya ฦ™irฦ™irar aiki daidai don yin aiki iri ษ—aya a cikin aikin zamani.

#include &lt;stdio.h&gt;

void SetCursorPosition(int x, int y) 
{
    printf("33[%d;%dH", y, x);
}

void main()
{
    SetCursorPosition(10, 20);
    printf("Hello, World!");
}

An gurษ“ata cikin aikin `SetCursorPosition()`, `printf("33[%d;%dH", y, x);' lambar tserewa ce ta ANSI wacce ke da tallafi da yawa kuma tana yin irin wannan aiki ga 'gotoxy' a cikin yanayi na zamani. Lambobin `y` da `x` suna ฦ™ayyadadden haษ—in kai.

Wannan aikin 'SetCursorPosition', daidai da 'gotoxy', yana ba ku damar sarrafa daidaiton wuri na fitarwa akan allon wasan bidiyo da aka keษ“e ta ฦ™imar (x, y). 'Printf' mai zuwa yana buga kirtani "Sannu, Duniya!" dama a waษ—ancan ฦ™ayyadaddun haษ—in gwiwar.

Amfani da waษ—annan ayyukan na iya taimakawa ฦ™irฦ™irar abubuwan wasan bidiyo masu ban sha'awa na gani da samar da iko kai tsaye akan matsayi ko rubutu. Wannan yana da matukar amfani wajen gina hadaddun ayyukan shirye-shirye.

Tunawa da cewa kowane aikin C da ษ—akin karatu yana kawo saiti na fa'idodi na musamman ga tebur, haษ“aka amfani da waษ—annan kayan aikin na iya haษ“aka ingantaccen aiki, daidaito, da ฦ™irฦ™ira a matsayin mai tsara shirye-shirye a C.

Shafi posts:

Leave a Comment