تبليغاتX
C++ برنامه نویسی کاربردی به زبان
C++ Learning
:: معرفی چند تابع کاربردی 

با سلام , امروز می خواهم چند تابع جدید را به شما معرفی کنم :

1. clreol : این تابع تمام کاراکترها که بعد از مکان نما قرار دارد را تا آخر آن خط پاک میکند بدون آنکه موقعیت مکان نما تغییر کند . علت اینکه من از تابع cptintf در مثال زیر استفاده کردم این است که توابع clreol - clrscr و getch هر سه در کتابخانه Conio.H هستند و تابع cprintf هم در این کتابخانه است و دیگر از printf استفاده نکردم همچنین یکی دیگر از مزیت های cprintf این است که برای چاپ text های رنگی در خروجی از این تابع استفاده می شود , در حالیکه printf چنین امکانی را در اختیارمان قرار نمی دهد . در زیر مثالی ارائه شده تا مفهوم تابع clreol را بهتر متوجه شوید :

#include <stdlib.h>

int main(void)

{
   clrscr();
   textcolor(10);
   cprintf("The function CLREOL clears all characters from the\r\n");
   cprintf("cursor position to the end of the line within the\r\n");
   cprintf("current text window, without moving the cursor.\r\n");
   cprintf("Press any key to continue . . .");
   gotoxy(14,4);
   getch();

   clreol();

   getch();
   return 0;
}


2 . delline : این تابع سبب می شود که خطی که مکان نما (Cursor) در آن قرار دارد حذف شود . برای تفهیم بیشتر به مثال زیر توجه کنید :

#include <stdlib.h>
int main(void)
{
   clrscr();
   textcolor(12);
   cprintf("The function DELLINE deletes the line containing the\r\n");
   cprintf("cursor and moves all lines below it one line up.\r\n");
   cprintf("DELLINE operates within the currently active text\r\n");
   cprintf("window.  Press any key to continue . . .");
   gotoxy(1,2);
/* Move the cursor to the second line and first column */
  
getch();

   delline();

   getch();
   return 0;
}


3 . insline : با استفاده از این تابع می توان یک خط خالی در بالای مکانی که مکان نما قرار دارد ایجاد کرد . به مثال زیر توجه کنید :

#include <stdlib.h>
int main(void)
{
   clrscr();
   textcolor(12);
   cprintf("The function DELLINE deletes line containing the\r\n");
   cprintf("cursor and moves all lines below it one line up.\r\n");
   cprintf("DELLINE operates within the currently active text\r\n");
   cprintf("window.  Press any key to continue . . .");
   gotoxy(1,2);
/* Move the cursor to the second line and first column */
  
getch();

   delline();

   getch();
   return 0;
}

 (*) Header هر سه تابع بالا می باشد .


4 . textmode : این تابع نوع نمایش text در صفحه نمایش را کنترل می کند . مقادیر قابل پذیرش این تابع را در جدول زیر مشاهده می کنید .

ثابت
مقدار عددی
نوع حالت
LASTMODE
-1
Previous text mode
40 columns
BW40
0
Black and white
40 columns
C40
1
Color
80 columns
BW80
2
Black and white
80 columns
C80
3
Color
80 columns
MONO
7
Monochrome
43 columns
C4350
64
EGA and VGA
50 columns

:: چگونگی عملکرد این تابع را میتوانید در مثال زیر ببینید :

#include <stdlib.h>
int main(void)
   {
    clrscr();
    textmode(BW40);
    textcolor(12);
    cprintf("Textmode >>>> (BW40)");
    getch();


    textmode(BW80);
    textcolor(10);
    cprintf("Textmode >>>> (BW80)");
    getch();

    textmode(C40);
    textcolor(11);
    cprintf("Textmode >>>> (C40)");
    getch();

    textmode(MONO);
    textcolor(14);
    cprintf("Textmode >>>> (MONO)");
    getch();

    return 0;
   }


 :: معرفی چند تابع برای تبدیل انواع داده ها :

نام تابع
شرح وظیفه
Header مورد نیاز
atof
برای تبدیل یک رشته به عدد اعشاری
Atoi
تبدیل رشته به عددی از نوع Integer
Atol
تبدیل رشته به عددی از نوع Long
ecvt and fcvt
تبدیل عدد اعشاری به رشته
gcvt
تبدیل عدد اعشاری به رشته
strtod
تبدیل رشته به عدد اعشاری از نوع Double
strtol
تبدیل رشته به عددی از نوع Long
_strtold
تبدیل رشته به long double
strtoul
تبدیل رشته به unsigned long

 


|+| نوشته شده توسط پژمان رودخانه ای در دوشنبه بیستم تیر 1384 و ساعت 2:20  
بالا