?? 王大剛--c語言編程寶典--l.htm
字號(hào):
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR>
<P>函數(shù)名: localtime <BR>功 能: 把日期和時(shí)間轉(zhuǎn)變?yōu)榻Y(jié)構(gòu) <BR>用 法: struct tm
*localtime(long *clock); <BR>程序例: <BR>
<P>#include <time.h> <BR>#include <stdio.h> <BR>#include
<dos.h> <BR>
<P>int main(void) <BR>{ <BR> time_t timer; <BR>
struct tm *tblock; <BR>
<P> /* gets time of day */ <BR> timer =
time(NULL); <BR>
<P> /* converts date/time to a structure */ <BR>
tblock = localtime(&timer); <BR>
<P> printf("Local time is: %s", asctime(tblock)); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: lock <BR>功 能: 設(shè)置文件共享鎖 <BR>用 法: int lock(int handle,
long offset, long length); <BR>程序例: <BR>
<P>#include <io.h> <BR>#include <fcntl.h> <BR>#include
<sys\stat.h> <BR>#include <process.h> <BR>#include
<share.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> int handle, status;
<BR> long length; <BR>
<P> /* Must have DOS Share.exe loaded for */ <BR>
/* file locking to function properly */ <BR>
<P> handle = sopen("c:\\autoexec.bat",
<BR> O_RDONLY,SH_DENYNO,S_IREAD); <BR>
<P> if (handle < 0) <BR> {
<BR> printf("sopen failed\n");
<BR> exit(1); <BR> } <BR>
<P> length = filelength(handle); <BR> status =
lock(handle,0L,length/2); <BR>
<P> if (status == 0) <BR>
printf("lock succeeded\n"); <BR> else
<BR> printf("lock failed\n"); <BR>
<P> status = unlock(handle,0L,length/2); <BR>
<P> if (status == 0) <BR>
printf("unlock succeeded\n"); <BR> else
<BR> printf("unlock failed\n"); <BR>
<P> close(handle); <BR> return 0; <BR>} <BR>
<BR> <BR>
<P>函數(shù)名: log <BR>功 能: 對(duì)數(shù)函數(shù)ln(x) <BR>用 法: double log(double x);
<BR>程序例: <BR>
<P>#include <math.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> double result; <BR>
double x = 8.6872; <BR>
<P> result = log(x); <BR> printf("The natural log
of %lf is %lf\n", x, result); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函數(shù)名: log10 <BR>功 能: 對(duì)數(shù)函數(shù)log <BR>用 法: double log10(double
x); <BR>程序例: <BR>
<P>#include <math.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> double result; <BR>
double x = 800.6872; <BR>
<P> result = log10(x); <BR> printf("The common log
of %lf is %lf\n", x, result); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: longjump <BR>功 能: 執(zhí)行非局部轉(zhuǎn)移 <BR>用 法: void
longjump(jmp_buf env, int val); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <setjmp.h> <BR>#include
<stdlib.h> <BR>
<P>void subroutine(jmp_buf); <BR>
<P>int main(void) <BR>{ <BR>
<P> int value; <BR> jmp_buf jumper; <BR>
<P> value = setjmp(jumper); <BR> if (value != 0)
<BR> { <BR> printf("Longjmp with
value %d\n", value); <BR> exit(value);
<BR> } <BR> printf("About to call subroutine ...
\n"); <BR> subroutine(jumper); <BR>
<P> return 0; <BR>} <BR>
<P>void subroutine(jmp_buf jumper) <BR>{ <BR>
longjmp(jumper,1); <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: lowvideo <BR>功 能: 選擇低亮度字符 <BR>用 法: void
lowvideo(void); <BR>程序例: <BR>
<P>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> clrscr(); <BR>
<P> highvideo(); <BR> cprintf("High Intesity
Text\r\n"); <BR> lowvideo(); <BR> gotoxy(1,2);
<BR> cprintf("Low Intensity Text\r\n"); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: lrotl, _lrotl <BR>功 能: 將無符號(hào)長整型數(shù)向左循環(huán)移位 <BR>用 法:
unsigned long lrotl(unsigned long lvalue, int count); <BR> unsigned
long _lrotl(unsigned long lvalue, int count); <BR>程序例: <BR>
<P>/* lrotl example */ <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>
<P>int main(void) <BR>{ <BR> unsigned long result;
<BR> unsigned long value = 100; <BR>
<P> result = _lrotl(value,1); <BR> printf("The
value %lu rotated left one bit is: %lu\n", value, result); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函數(shù)名: lsearch <BR>功 能: 線性搜索 <BR>用 法: void *lsearch(const
void *key, void *base, size_t *nelem,
<BR> size_t width, int (*fcmp)(const
void *, const void *)); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <stdlib.h> <BR>
<P>int compare(int *x, int *y) <BR>{ <BR> return( *x - *y );
<BR>} <BR>
<P>int main(void) <BR>{ <BR> int array[5] = {35, 87, 46, 99,
12}; <BR> size_t nelem = 5; <BR> int key;
<BR> int *result; <BR>
<P> key = 99; <BR> result = lfind(&key, array,
&nelem,
<BR>
sizeof(int), (int(*)(const void *,const void *))compare); <BR>
if (result) <BR> printf("Number %d
found\n",key); <BR> else <BR>
printf("Number %d not found\n",key); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: lseek <BR>功 能: 移動(dòng)文件讀/寫指針 <BR>用 法: long lseek(int
handle, long offset, int fromwhere); <BR>程序例: <BR>
<P>#include <sys\stat.h> <BR>#include <string.h> <BR>#include
<stdio.h> <BR>#include <fcntl.h> <BR>#include <io.h>
<BR>
<P>int main(void) <BR>{ <BR> int handle; <BR> char
msg[] = "This is a test"; <BR> char ch; <BR>
<P> /* create a file */ <BR> handle =
open("TEST.$$$", O_CREAT | O_RDWR, S_IREAD | S_IWRITE); <BR>
<P> /* write some data to the file */ <BR>
write(handle, msg, strlen(msg)); <BR>
<P> /* seek to the begining of the file */ <BR>
lseek(handle, 0L, SEEK_SET); <BR>
<P> /* reads chars from the file until we hit EOF */
<BR> do <BR> { <BR>
read(handle, &ch, 1); <BR> printf("%c",
ch); <BR> } while (!eof(handle)); <BR>
<P> close(handle); <BR> return 0; <BR>} <BR>
<BR>
<HR width="94%" color=#ee9b73 SIZE=1>
</TD>
<TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/031.htm">后一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/029.htm">前一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目錄</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首頁</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -