
labs

㭪            頥 ᮫⭮ 祭  楫
                   ᫠.

⠪          #include<math.h>
                   long int labs(long int x);

, ᮤঠ騩   math.h, stdlib.h
⨯

ᠭ           labs  ᮫⭮ 祭 ࠬ .

頥       頥 ᮫⭮ 祭 .
祭

७ᨬ      labs 㯭  ⥬ UNIX  ন
                   ⠭⮬ ANSI C.

 ⠪     abs, cabs, fabs.

ਬ:

#include<stdio.h>
#include<math.h>

int main(void)
{
   long result;
   long x = -12345678L;
   result = labs(x);
   printf("᫮: %ld, ᮫⭮ 祭 :%ld\n",
         x,result);
   return 0;
}


ldexp

㭪             祭 x * 2^exp.

⠪          #include<math.h>
                   double ldexp(double x, int exp);

, ᮤঠ騩   math.h
⨯

ᠭ           ldexp  祭  筮 x*2^exp.

頥        ᯥ譮 襭 ldexp 頥 ᫥-
祭            祭 x*2^exp.

                   ࠡ 訡      ldexp      
                    㭪樨 matherr.

७ᨬ      㭪 ldexp ন  ⥬ UNIX  ⠭-
                   ⮬ ANSI C.

 ⠪     exp, frexp, modf.

ਬ:

#include<stdio.h>
#include<math.h>

int main(void)
{
   double valus;
   double x = 2;
   /* ldexp  2  ⥯ 3,  ⥬ 㬭
      १  2 */
   value = ldexp(x);
   printf("祭 ldexp = %lf\n",value);
   return 0;
}


ldiv

㭪               楫, 頥 ⭮ 
                   ⮪.

⠪          #include<stdlib.h>
                   ldiv_t ldiv(long int numer, long int denom);

 ᮤঠ騩    stdlib.h
⨯

ᠭ           ldiv    楫  頥 ⭮ 
                   ⮪   ⨯ ldiv_t. ࠬ numer 
                   denom -  ⭮  ⥫ ᮮ⢥⢥. 
                   ldiv_t  ।    䠩  stdlib.h  (  
                    typedef) ᫥騬 ࠧ:

                   typedef struct {
                     long int quot;              /* ⭮ */
                     long int rem;               /* ⮪ */
                   } ldiv_t;

頥       ldiv 頥 ,  ன ᮤ-
祭            ⭮  ⮪.

७ᨬ      ldiv ন ⠭⮬ ANSI C.

 ⠪     div.

ਬ:

#include<stdlib.h>
#include<stdio.h>

int main(void)
{
   ldiv_t lx;
   lx = ldiv(100000L, 30000L);
   printf("100000 div 30000 = %ld, ⮪ = %ld\n",
                                         lx.quot, lx.rem);
   return 0;
}


lfind

㭪            믮  .

⠪          #include<stdlib.h>
                   void *lfind(const void *key, const void *base,
                           size_t *num, size_t width,
                           int(*fcmp)(const void *,const void *));

, ᮤঠ騩   stdlib.h
⨯
                   
ᠭ           lfind ந     祭 key 
                   ᨢ ᫥⥫ ᥩ.    ᯮ
                   ।   짮⥫  ணࠬ  ࠢ
                   (fcmp).

                   ᨢ 뢠         ᮤঠ騩   *num
                   ᥩ,  ਭ width . base 㪠뢠
                   砫 ᨢ.

頥       lfind 頥  ࢮ, ᮢ饣  -
祭           , . ᫨ ᮢ  㦥, 
                   lfind 頥   NULL.   ணࠬ  ࠢ
                      0  ᫨  *elem1  ==  *elem2,  
                   㫥  祭   ⨢ 砥.  (elem1 
                   elem2   ࠬ).

७ᨬ      lfind 㭨쭠  DOS.

 ⠪     bsearch, lsearch, qsort.

ਬ:

#pragma warn -rpt
#include<stdio.h>
#include<stdlib.h>

int compare(int *x,int *y)
{
   return(*x-*y);
}
int main(void)
{
   int array[5] = {35,87,46,99,12};
   int key;
   int *result;
   key = 99;
   result = lfind(&key,array,5,sizeof(int),compare);
   if(result)
      printf("᫮ %d ",key);
   else
      printf("᫮ %d ",key);
   return 0;
}


line

㭪                㪠묨 窠.

⠪          #include <graphics.h>
                   void far line(int x1, int y1, int x2, int y2);

, ᮤঠ騩   graphics.h
⨯

ᠭ           line  ,  ᯮ ⥪騥 梥,  ⨯ 
                   ⮫騭 ,    窠, ।묨
                    (x1,  y1)    (x2,  y2),      ⥪
                    (CP).

頥       .
祭

७ᨬ      㭪 㭨쭠  Borland  C++.    ࠡ⠥
                   ⮫쪮   IBM PC  ᮢ⨬  ,
                   ᭠饭 ᯫ묨 ࠬ, ন騬
                   ᪨   ०.   㭪     ᮢ⨬  
                   Windows.

 ⠪     getlinesettings, linerel, lineto, setcolor,
                   setlinestyle, setwritemode.

ਬ:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
/*  ⮮। */
int graphdriver = DETECT, gmode, errorcode;
int xmax,ymax;

/* 樠 䨪   ६ */
initgraph(&graphdriver,&gmode,"");

/* 祭 १ 樠樨 */
errorcode = graphresult();
if(errorcode != grOk)  /* ᫨ 訡 */
{
   printf("訡 :%s\n",grapherrormessage(errorcode));
   printf(" ⠭   \n");
   getch();
   exit(1);  /* 襭   訡 */
}
setcolor(getmaxcolor(1));
xmax = getmaxx();
ymax = getmaxy();

/* ᮢ   */
line(0,0,xmax,ymax);

/* ⪠ */
getch();
closegraph();
return 0;
}


linerel

㭪                ﭨ  ⥪饩
                   樨 (CP).

⠪          #include <graphics.h>
                   void far linerel(int dx, int dy);

, ᮤঠ騩   graphics.h
⨯

ᠭ           linerel     CP  窨,  室饩
                    ﭨ (dx,  dy)  CP.  CP ६頥 
                   CP + (dx,dy).

頥       H.
祭

७ᨬ      㭪 㭨쭠  Borland  C++.    ࠡ⠥
                   ⮫쪮   IBM PC  ᮢ⨬  ,
                   ᭠饭 ᯫ묨 ࠬ, ন騬
                   ᪨  ०.  㭪      ᮢ⨬   
                   Windows.

 ⠪     getlinesettings,    line,   lineto,   setcolor
                   setlinestyle, setwritemode.

ਬ:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
/*  ⮮। */
int graphdriver = DETECT, gmode, errorcode;
char msg[80];

/* 樠 䨪   ६ */
initgraph(&graphdriver,&gmode,"");

/* 祭 १ 樠樨 */
errorcode = graphresult();
if(errorcode != grOk)  /* ᫨ 訡 */
{
   printf("訡 :%s\n",grapherrormessage(errorcode));
   printf(" ⠭   \n");
   getch();
   exit(1);  /* 襭   訡 */
}
/* ६ ⥪  (CP)   (20,30) */
moveto(20,30);
/* ᮧ ப  ᮮ饭 */
sprintf(msg," (%d,%d)",getx(),gety());
outtextxy(20,30,msg);
/* ᮢ  ⭮⥫쭮 ⥪饩 樨 */
linerel(100,100);
/* ᮧ ப  ᮮ饭 */
sprintf(msg," (%d,%d)",getx(),gety());
outtext(msg);

/* ⪠ */
getch();
closegraph();
return 0;
}


lineto

㭪               ⥪饩 樨  (CP)      
                   न⠬ (x,y).

⠪          #include <graphics.h>
                   void far lineto(int x, int y);

, ᮤঠ騩   graphics.h
⨯

ᠭ           lineto    CP  窨  न⠬
                   (x,y), ⥬ ७ (CP)  (x,y).

頥       .
祭

७ᨬ      㭪 㭨쭠    Borland C++.   ࠡ⠥
                   ⮫쪮   IBM PC  ᮢ⨬  ,
                   ᭠饭 ᯫ묨 ࠬ, ন騬
                   ᪨   ०.   㭪     ᮢ⨬  
                   Windows.

 ⠪       getlinesettings,   line,   linerel,   setcolor,
                   setlinestyle, setvisualpage, setwritemode.

ਬ:

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
/*  ⮮। */
int graphdriver = DETECT, gmode, errorcode;
char msg[80];

/* 樠 䨪   ६ */
initgraph(&graphdriver,&gmode,"");

/* 祭 १ 樠樨 */
errorcode = graphresult();
if(errorcode != grOk)  /* ᫨ 訡 */
{
   printf("訡 :%s\n",grapherrormessage(errorcode));
   printf(" ⠭   \n");
   getch();
   exit(1);  /* 襭   訡 */
}
/* ६ ⥪  (CP)   (20,30) */
moveto(20,30);
/* ᮧ ப  ᮮ饭 */
sprintf(msg," (%d,%d)",getx(),gety());
outtextxy(20,30,msg);
/* ᮢ  ⭮⥫쭮 ⥪饩 樨 */
lineto(100,100);
/* ᮧ ப  ᮮ饭 */
sprintf(msg," (%d,%d)",getx(),gety());
outtext(msg);

/* ⪠ */
getch();
closegraph();
return 0;
}


localeconv

㭪            頥 㪠⥫  ⥪  locale.

⠪          #include<locale.h>
                   struct lconv *localeconv(void);

, ᮤঠ騩   locale.h
⨯

ᠭ            㭪  ⠭  ଠ  뢮  業 
                   㣨 ᫮  ଠ.    Borland  C++  
                   饥 ६ ন ⮫쪮 locale C.

頥       頥 㪠⥫  ⥪  locale.
祭           ⥫ ଠ    䠩
                   locale.h.

७ᨬ      localeconv ন ⠭⮬ ANSI C.

 ⠪     setlocale.

ਬ:

#include<locale.h>
#include<stdio.h>

int main(void)
{
   struct lconv ll;
   struct lconv *conv = ll;
   /*     */
   conv = localeconv();
   /* ᯥ ᮤন */
   printf("筠 窠             : %s\n,conv->desimal_point);
   printf("⥫             : %s\n,conv->thousands_sep);
   printf("㯯஢                : %s\n,conv->grouping);
   printf("㭠த ᨬ   : %s\n,conv->int_curr_sumbol);
   printf("$ ࠧ⥫           : %s\n,conv->mon_thounsands_sep);
   printf("$ 㯯஢              : %s\n,conv->mon_grouping);
   printf("⥫            : %s\n,conv->positive_sign);
   printf("⥫            : %s\n,conv->negative_sign);
   printf("㭠த  ᨬ.: %d\n,conv->int_frac_digits);
   printf(" ᫠              : %d\n,conv->frac_digits);
   printf("।⢮ ᨬ . : %d\n,conv->p_cs_precedes);
   printf("⥫ .      : %d\n,conv->p_sep_by_space);
   printf("।⢮ ᨬ . : %d\n,conv->n_cs_precedes);
   printf("⥫ .    : %d\n,conv->n_sep_by_space);
   printf(" ⥫쭮  : %d\n,conv->p_sign_posn);
   printf(" ⥫쭮  : %d\n,conv->n_sign_posn);
   return 0;
}


localtime

㭪            ८ࠧ   ६  .

⠪          #include <time.h>
                   struct tm *localtime(const time_t * clock);

, ᮤঠ騩   time.h
⨯

ᠭ           localtime 砥    祭  頥
                   㭪樥 time  頥 㪠⥫   
                   ⨯ tm,  ᮤঠ ࠧ ६.  localtime
                   ८ࠧ  ६    ⭮  ६    
                     ⭥ ६.

                   쭠 ६ ⨯  long  timezone  
                   ᮤঠ  ࠧ    ᥪ㭤   ६ 
                   ਭ   ६. 쭠 ६
                   daylight   ࠢ 0, ᫨  ᯮ
                   ⠭⭮ ⭥ ६.

                    tm         time.h   ᫥騬
                   ࠧ:

                   struct tm {
                   int tm_sec;
                   int tm_min;
                   int tm_hour;
                   int tm_mday;
                   int tm_mon;
                   int tm_year;
                   int tm_wday;
                   int tm_yday;
                   int tm_isdst;
                   };

                      ᮤঠ  ६  24-ᮢ ,
                       1-31,     1-12,      
                   (ᥭ = 0),   - 1900,   0-365, 
                   䫠, ।騩   ⭥ ६.

頥       localtime 頥 㪠⥫  ,
祭           ᮤঠ ࠧ ६.   
                     static  १뢠   
                   맮.

७ᨬ      localtime 㯭  ⥬ UNIX  ন
                   ⠭⮬ ANSI C.

 ⠪     asctime, ctime, gmtime, ftime, stime, time, tzset.

ਬ:

#include<stdio.h>
#include<time.h>
#include<dos.h>

int main(void)
{
time_t     timer;
struct tm  *tblock;
timer = time(NULL);
tblock = localtime(&timer);
printf("⭮ ६: %s",asctime(tblock));
return 0;
}


lock

㭪                䠩.

⠪          #include<io.h>
                   int lock(int handle, long offset, long length);

, ᮤঠ騩   io.h
⨯

ᠭ           lock         ᯮ짮     堭
                   ࠧ  㯠   䠩   DOS 3.x.
                   ।  ᯮ짮  ⮩   㭪樨   室
                   㧨 SHARE.EXE.

                      㭪樨  ஢ 
                   ४뢠騥       䠩.   ணࠬ,
                       뢠        뢠     
                   ஢   䠩,    ⪨.
                   ᫨      ⪨  稫  㤠祩,  
                    稢  訡.

頥       㭪 頥 0  ᯥ譮 襭, 
祭           -1  訡.

७ᨬ      㭪 㭨쭠  ⥬ DOS ᨩ 3.x. 
                   ࠭ ᨨ DOS  ন  맮.

 ⠪     open, sopen, unlock.

ਬ:

#include<io.h>
#include<fcntl.h>
#include<sys\stat.h>
#include<process.h>
#include<share.h>
#include<stdio.h>

int main(void)
{
    int handle,status;
    long length;
    /*  প ࠧ 䠩 室 ।-
       ⥫쭮 㧨 SHARE.EXE. */
    handle = sopen("c:\\autoexec.bat",
         O_RDONLY, SH_DENYNO, S_IREAD);
    if(!handle)
    {
        printf("訡  樨 sopen");
        exit(1);
    }
    length = filelength(handle);
    status = lock(handle,0L,length/2);
    if(status == 0)
        printf("ᯥ譠  ஢");
    else
        printf("訡  樨 ஢");
    status = unlock(handle,0L,length/2);
    if(status == 0)
        printf("ᯥ譠  ࠧ஢");
    else
        printf("訡  樨 ࠧ஢");
    close(handle);
    return 0;
}


log

㭪             ࠫ  ln(x).

⠪            ⢥      
                   #include<math.h>           #include<complex.h>
                   double log(double x);      complex log(complex x);

, ᮤঠ騩     ⢥      
⨯           math.h                     complex.h

ᠭ           log  ࠫ   .

                   ࠫ            ᥫ
                   । ᫥騬 ࠧ:

                      log(z) = log(abs(z)) + i arg(z)

頥        ᯥ譮 襭 log 頥 ᫥
祭           祭 (ln(x)). ᫨ 㬥  ।
                   㭪樨 log    0,    쭮 ६
                   errno ᢠ 祭:

                          EDOM - 訡  ।.

                   log(0) 頥  祭  ⭮  HUGE_VAL  
                   ᢠ  쭮  ६ errno 祭
                   ERANGE.

                   ࠡ 訡   㭪樨  
                     㭪樨 matherr.

७ᨬ       log    ⢥  ᥫ  㯭   
                   ⥬  UNIX  ন ⠭⮬ ANSI C.
                   ᭠  log ॡ ++ , ᪮॥ ᥣ
                    ७ᨬ.

 ⠪     complex, exp, log10, sqrt.

ਬ:

#include<math.h>
#include<stdio.h>

int main(void)
{
   double result;
   double x = 8.6872;
   result = log(x);
   printf("ࠫ   %lf ࠢ %lf\n",x,result);
   return 0;
}


log10

㭪               log10(x).

⠪            ⢥    
                   #include<math.h>         #include<complex.h>
                   double log10(double x);  complex log10(complex x);

, ᮤঠ騩     ⢥    
⨯           math.h                   complex.h

ᠭ           log10     .

                           ᭮       ᫠
                   । ᫥騬 ࠧ:

                   log10(z) = log(z)/log(10)

頥        ᯥ譮 襭 log10 頥 ᫥-
祭            祭 (log10(x)). ᫨ 㬥  ।-
                    㭪樨   log10    0,    쭮
                   ६ errno ᢠ 祭:

                          EDOM - 訡  ।.

                   log10(0) 頥 祭 ⭮ HUGE_VAL.

                   ࠡ 訡   㭪樨  
                     㭪樨 matherr.

७ᨬ       log10   ⢥  ᥫ  㯭  
                   ⥬  UNIX  ন ⠭⮬ ANSI C.
                   ᭠  log10  ॡ  ++    ⮬
                   ᪮॥ ᥣ  ७ᨬ.

 ⠪     complex, exp, log.

ਬ:

#include<math.h>
#include<stdio.h>

int main(void)
{
   double result;
   double x = 800.6872;
   result = log10(x);
   printf("   %lf ࠢ %lf\n",x,result);
   return 0;
}


longjmp

㭪            믮  室.

⠪          #include <setjmp.h>
                   void longjmp(jmp_buf jmpb, int retval);

, ᮤঠ騩   setjmp.h
⨯

ᠭ           맮 㭪樨  longjmp  ⠭  ﭨ
                   ,  ஥  뫮  ⠭   ᫥
                   맮 㭪樨 setjmp  㬥⮬ jmpb. ⥬ 
                   頥  祭  retval ⠪,    㭪
                   setjmp.

                   Cﭨ  ।⠢ ᮡ ᫥饥:

                   -  ᥣ ॣ (CX,DS,ES,SS);
                   - ६-ॣ (SI,DI);
                   - 㪠⥫ ⥪ (SP);
                   - 㪠⥫  (BP);
                   - 䫠.

                   ﭨ    筮 ,  ⠪
                     㭪樨   setjmp      longjmp      
                   ᯮ짮      㬥     ࣠樨
                   ᮯணࠬ.  ணࠬ   
                       ࠡ      訡      ᪫⥫묨
                   ﬨ,   ந室騬        ஢
                   ணࠬ ਪ ணࠬ.

                   । ᯮ짮  㭪樨  longjmp  室
                   맢  㭪  setjmp.   ணࠬ   뢠
                   setjmp    ⠭  jmpb  ⠢
                   ⨢         ࠢ  
                   맮  longjmp.  ᫨  ,   १
                   ।᪠㥬.

                   longjmp     뫠  祭  0.  ᫨  0
                   뫠  retval,     1.

                   ਬ砭. 㭪樨   setjmp      longjmp  
                   ᯮ짮  ॠ樨  ૥  ணࠬ.
                   筮    setjmp        longjmp    ࠭    
                   ⠭ ,  室  ॠ樨
                   ᮯணࠬ,         ࠢ  ૥ﬨ
                   室    ᫥         ⥪,     祬
                   ࠧ㬥,    ⥪  .   ॠ樨
                   ᮯணࠬ  筮 ᯮ    ⥪,  
                        ⥪,   ⮬ 
                   ૥  ᬮ ४⭮  ᫥.

                        ,  ࠡ騥     䮭
                   ०,    ᯮ  ᢮ ⥪,   ᢮
                   ࠧ  饣  ⥪,          
                   㢥७,     ᯮ ૥,    
                    ᯮ짮  ૥  ᨨ  setjmp  
                   longjmp  ४祭   䮭 .

頥       .
祭

७ᨬ      㭪 ন       ⥬   UNIX   
                   ⠭⮬  ANSI  C.  㭪     ᮢ⨬   
                   Windows.

 ⠪     ctrlbrk, setjmp, signal.

ਬ:

#include <stdio.h>
#include <setjmp.h>

int main(void)
{
   jmp_buf jumper;
   int value;
   value = setjmp(jumper);
   if (value != 0) {
     printf("longjmp  祭 %d\n", value);
     exit(value);
   }
   printf("맮 ணࠬ ... \n");
   subroutine();
}
subroutine()
{
   longjmp(jumper,l);
}

뢮:

맮 ணࠬ ...
Longjmp  祭 l


lowvideo

㭪            ⠭     ⥭ᨢ    뢮
                   ᨬ.

⠪          #include<conio.h>
                   void lowvideo(void);

 ᮤঠ騩    conio.h
⨯

ᠭ           lowvideo       ⥭ᨢ      
                   ਡ⮢ ⥪饣 梥 ᨬ.

                   맮 ⮩ 㭪樨   ࠦ      ⥪,
                   室饬    ࠭,    ⮫쪮   १
                   ࠡ 㭪権,  ந  뢮    ⥪⮢
                   ०   ᮫,   ⮫쪮 ᫥ 맮 㭪樨
                   lowvideo.

頥       .
祭

७ᨬ      lowvideo ࠡ⠥    ⮫쪮          
                   ᮢ⨬   IBM PC.  筠 㭪樨  
                   Turbo Pascal. 㭪  ᮢ⨬  Windows.

 ⠪     highvideo, normvideo, textattr, textcolor.

ਬ:

#include<conio.h>

int main(void)
{
   clrscr();
   lowvideo();
   cprintf("  ⥭ᨢ");
   highvideo();
   gotoxy(1,2);
   cprintf(" ᮪ ⥭ᨢ");
   return 0;
}


_lrotl

㭪            ᪨ ᤢ   楫.

⠪          #include<stdlib.h>
                   unsigned long _lrotl(unsigned long val,int count);

 ᮤঠ騩    stdlib.h
⨯

ᠭ           _lrotl ந 横᪨ ᤢ   count
                   . val  ⨯ unsigned long.

頥       _lrotl 頥 祭 val ᤢ⮥  
祭           count .

७ᨬ      _lrotl 㭨쭠  DOS.

 ⠪     _lrotr, _rotl, _rotr.

ਬ:

#include<stdlib.h>
#include<stdio.h>

int main(void)
{
   unsigned long result;
   unsigned long value = 100;
   result = _lrotl(value,1);
   printf("祭 %lu ᤢ⮥   1  ࠢ %lu\n",
           value,result);
   return 0;
}


_lrotr

㭪            ᪨ ᤢ ࠢ  楫.

⠪          #include<stdlib.h>
                   unsigned long_lrotr(unsigned long val, int count);

 ᮤঠ騩    stdlib.h
⨯

ᠭ           _lrotr ந 横᪨ ᤢ ࠢ  count
                   . val  ⨯ unsigned long.

頥       _lrotr 頥 祭 val ᤢ⮥  
祭           count .

७ᨬ      _lrotl 㭨쭠  DOS.

 ⠪     _lrotl, _rotl, _rotr.

ਬ:

#include<stdlib.h>
#include<stdio.h>

int main(void)
{
   unsigned long result;
   unsigned long value = 100;
   result = _lrotr(value,1);
   printf("祭 %lu ᤢ⮥ ࠢ  1  ࠢ %lu\n",
           value,result);
   return 0;
}


lsearch

㭪            믮  .

⠪          #include<stdlib.h>
                   void *lsearch(const void *key, void *base,
                         size_t num, size_t width,
                         int(*fcmp)(const void *, const void *));

, ᮤঠ騩   stdlib.h
⨯

ᠭ           lsearch ந  ᬮ  ⠡.  ..   
                    ,   ⠡   
                   ஢, । 맮 㭪樨 lsearch. ᫨
                   ,      㪠뢠 key,    
                   ⠡,  lsearch    .

                   base -   㪠⥫      (0-  )
                          ⠡.

                   num - 㪠뢠   楫  祭,  ।饥
                         ᫮ ⮢  ⠡.

                   key - 㪠뢠  ᪮ .

                   wight- ᮤন ࠧ  ⠡  .

                   㬥 fcmp  㪠뢠    ணࠬ  ࠢ
                   ᠭ 짮⥫.      ࠢ
                       १ ࠢ.

                    ᬮ  ⠡  lsearch 뢠 ணࠬ
                   ࠢ,   㪠뢠 㬥 fcmp.

                      맮  ணࠬ  ࠢ   lsearch
                   뫠      ࠬ:  key - 㪠⥫ 
                   ᪮ ,   elem - 㪠⥫    
                   ⠡.

                   fcmp   ஢  祭 ࠬ
                    ⥬.

頥       lsearch 頥  ࢮ   ⠡-
祭           , ᮢ饣  ᪮.

                   ᫨ key ᮢ  elem,  fcmp 頥 0, 
                   ⨢   砥   fcmp   頥   㫥
                   祭.

७ᨬ      lsearch 㯭  ⥬ UNIX.

 ⠪     bsearch, lfind.

ਬ:

#include<stdlib.h>
#include<stdio.h>
#include<string.h>

/* 樠஢ ᫮ 梥⮢ */
char *color[10] = {"Red","Blue","Green"};
int ncolors = 3;

int colorscmp(char **arg1, char **arg2)
{
  return(strcmp(*arg1,*arg2));
}

int addelem(char *color)
{
  int oldn = ncolors;
  lsearch(&color, colors, (size_t*)&colors,
                 sizeof(char*), colorscmp);
  return(ncolors = oldn);
}

int main(void)
{
  int i;
  char *key = "Purple";

  if(addelem(key))
    printf("%s 㦥  ⠡", key);
else
    printf("%s   ⠡ 梥⮢ ",
            "⥯   %d 梥⮢",key,ncolors);
printf(":");
for(i=0; i<ncolors; i++)
    printf("%s\n",colors[i]);
}


lseek

㭪            ६頥 㪠⥫ ⥭/ 䠩.

⠪          #include <io.h>
                   long lseek(int handle, long offset,int fromwhere);

, ᮤঠ騩   io.h
⨯

ᠭ           㭪 lseek   ⠭   㪠⥫   䠩,
                   易  ࠬ஬ handle,      ,
                     室    offset ⮢ ⭮⥫쭮
                   ⮯    ࠬ஬   fromwhere.
                   ࠬ  fromwhere          
                   祭 0,  1  2,   ।⠢  ६
                   ᨬ᪨  ⠭⠬ (।묨  䠩
                   stdio.h) ᫥騬 ࠧ:

                   
                   ࠬ fromwhere       ᯮ
                                             䠩
                   
                   SEEK_SET      (0)        砫 䠩
                   SEEK_CUR      (1)        ⥪  㪠⥫
                                            䠩
                   SEEK_END      (2)         䠩
                   

頥       㭪 lseek 頥 祭 ᬥ饭 
祭           樨 㪠⥫, 塞    砫
                   䠩.   砥  訡  㭪 lseek 頥
                   祭  -1L     쭠   ६   errno
                   砥   ᫥ 祭:

                   EBADF   -   䠩.
                   EINVAL  -  㬥.

                    ன⢠, ਣ  ᪠, ⠪, 
                   ନ      ਭ,   頥  祭
                   ।.

७ᨬ      lseek ন   ⥬ UNIX.

 ⠪     filelength, fseek, ftell, getc, open, sopen,
                   ungetc, _write, write.

ਬ:

#include<sys\stat.h>
#include<string.h>
#include<stdio.h>
#include<fcntl.h>
#include<io.h>

int main(void)
{
   int handle;
   char msg[] = " ";
   char ch;
   /* ᮧ 䠩 */
   handle = open("TEST.$$$",O_CREAT|O_RDWR,S_IREAD|S_IWRITE);
   /* 뢥  䠩  */
   write(handle,msg,strlen(msg));
   /* ६ 㪠⥫  砫 䠩 */
   lseek(handle,0L,SEEK_SET);
   /* 뢠   䠩,   ⨬ EOF */
   do
   {
      read(handle,&ch,1);
      printf("%c",ch);
   } while(!eof(handle));
   close(handle);
   return 0;
}


ltoa

㭪            ८ࠧ   楫   祭      ப
                   ᨬ.

⠪          #include<stdlib.h>
                   char *ltoa(long value, char *string, int radix);

, ᮤঠ騩   stdlib.h
⨯

ᠭ            㭪  ८ࠧ  祭  value  ப
                   ᨬ,  稢  㫥,      뢠
                   १    ࠬ  string.    㭪樨 ltoa
                   祭 value -  楫.

                   ࠬ radix  ।  ,    㤥
                   ᯮ짮  ८ࠧ 祭 value;  
                        2  36 (⥫쭮).  E᫨
                   祭 value ⥫쭮,   祭 radix 10,
                    ᨬ ப string -   (-).

                   ਬ砭. ࠭⢮, 뤥塞  ࠬ
                   string     ,  ⮡  
                   祭    १  ࠡ  㭪樨 ப,
                    㫥    (\0).  㭪  ltoa  
                     33 .

頥       㭪 頥 㪠⥫  ப string.
祭

७ᨬ      ltoa 㭨쭠  DOS.

 ⠪     itoa, ultoa.

ਬ:

#include<stdlib.h>
#include<stdio.h>

int main(void)
{
   char string[25];
   long value = 123456789L;
   ltoa(value,string,10);
   printf("᫮ = %ld ப: %s\n",value,string);
   return 0;
}
