An warware: girman tasha a c

Duniyar shirye-shirye a cikin C ta kasance mai arziฦ™i mai ban sha'awa kuma mai sarฦ™aฦ™ฦ™iya, mai cike da manyan ayyuka waษ—anda ke biyan buฦ™atu daban-daban. ฦŠauka, alal misali, manufar girman tasha a cikin C. Ma'anar ta ta'allaka ne akan daidaita girman tashar tashar ko na'ura mai kwakwalwa a cikin harshen shirye-shiryen C. Wannan labarin yana zurfafa cikin tsari mai tsauri zuwa girman tasha a cikin C, yana ba da cikakken bayani mataki-mataki na lambar.

Don haka, me yasa girman tashar ke da mahimmanci? A cikin shirye-shiryen C, na'ura mai kwakwalwa ko tasha tana ba da hanyar sadarwa don mai amfani don mu'amala da shirin. Ana nuna masu sauye-sauye, nau'ikan bayanai, da sauran abubuwan da aka fitar a kan tashar. Yin la'akari da mahimmancinsa, samun tsabta da isasshen sarari akan na'ura mai kwakwalwa yana taimakawa wajen lura da abubuwan da aka fitar da kyau.

Fahimtar Girman Tasha

Zurfafa zurfafa cikin batun, fahimtar ainihin girman tasha a cikin C yana da mahimmanci. Girman tasha yana nufin adadin jere da abubuwan ginshiฦ™an da taga na'urar bidiyo za ta iya ษ—auka. Siffa ce da ke haษ“aka tsari da gabatar da abubuwan da ke bayyana kamanni da jin daษ—in na'urar wasan bidiyo.

Ayyuka kamar ioctl(), da aka ayyana a cikin ษ—akin karatu sys/ioctl.h, suna taka muhimmiyar rawa wajen maido da ma'auni na ฦ™arshe. Suna hulษ—a tare da sigogi na na'ura akan matakin mafi girma kuma suna ba da gudummawa sosai ga ayyukan I/O da yawa.

 
#include <sys/ioctl.h>
#include <stdio.h>

int main() {
    struct winsize w;
    ioctl(0, TIOCGWINSZ, &w);

    printf ("lines %dn", w.ws_row);
    printf ("columns %dn", w.ws_col);

    return 0;
}

Maganin Girman Tasha

ฦ˜ayyade girman Terminal a cikin C za a iya samun nasara sosai ta amfani da aikin ioctl (). Aikin yana mu'amala da girman tasha kuma yana mayar da adadin layuka da ginshiฦ™ai da ke akwai. Shirin yana amfani da kiran TIOCGWINSZ don buฦ™atar girman tasha kuma daga baya ya buga layin da aka samu da ฦ™imar shafi.

Kamar yadda aka gani a cikin samfurin code a sama, aikin ioctl() yana dawo da ma'aunin tasha kuma ana buga ma'aunin ta amfani da printf(). Ana amfani da wannan bayanan galibi don daidaita shimfidar abubuwan da aka fitar don mai amfani.

Bayanin Mataki-Ta-Taki na Code

Lambar tana da saukin kai. Anan ga matakin mataki-mataki:

A cikin layi na farko, ana shigo da dakunan karatu masu mahimmanci, sys/ioctl.h da stdio.h.

  • sys/ioctl.h ana shigo da shi don aikin ioctl().
  • stdio.h yana ba da ainihin shigarwa da ayyukan fitarwa

Bayan haka, an ayyana babban () aikin, yana nuna alamar shigarwar lambar. Anan ne shirin zai fara aiwatarwa.

In layi mai zuwa, struct winsize abu, w, an ayyana. Ana amfani da shi don yin mu'amala tare da aikin ioctl() da adana ma'aunin tasha.

Ana kiran aikin ioctl() tare da mahawara guda uku: 0, TIOCGWINSZ, da &w. Anan, 0 yana nufin bayanin fayil ษ—in don stdin, TIOCGWINSZ koyaushe ne wanda ke gaya wa ioctl don dawo da girman taga, kuma &w shine mai nuni ga tsarin winsize inda za'a adana girman.

Bayan yin hulษ—a tare da ma'auni na tashoshi ta amfani da ioctl, ana nuna girman tashar ( layuka da ginshiฦ™ai ) ta amfani da printf (), yana kammala cikakken tsari.

Wannan misali yana kwatanta yadda ake ษ—aukowa da daidaita girman tasha a cikin C. Ilimin girman tasha ya tabbatar da cewa yana da matuฦ™ar mahimmanci, yana taimakawa wajen ฦ™irฦ™irar mu'amalar abokantaka da mai amfani da haษ“aka damar gani na tashar.

Shafi posts:

Leave a Comment