?? 王大剛--c語言編程寶典--u.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/038.htm -->
<HTML><HEAD><TITLE>王大剛-->C語言編程寶典-->U</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大剛 C語言編程寶典 U" name=keywords>
<META content="王大剛 - C語言編程寶典 - U" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋體"
}
.tt2 {
FONT: 12pt/15pt "宋體"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/039.htm">后一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/037.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>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷體_GB2312
color=#ff6666>U</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<BR>
<P>函數(shù)名: ultoa <BR>功 能: 轉(zhuǎn)換一個無符號長整型數(shù)為字符串 <BR>用 法: char
*ultoa(unsigned long value, char *string, int radix); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>
<P>int main( void ) <BR>{ <BR> unsigned long lnumber =
3123456789L; <BR> char string[25]; <BR>
<P> ultoa(lnumber,string,10); <BR> printf("string
= %s unsigned long = %lu\n",string,lnumber); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: ungetc <BR>功 能: 把一個字符退回到輸入流中 <BR>用 法: int ungetc(char
c, FILE *stream); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <ctype.h> <BR>
<P>int main( void ) <BR>{ <BR> int i=0; <BR> char
ch; <BR>
<P> puts("Input an integer followed by a char:"); <BR>
<P> /* read chars until non digit or EOF */ <BR>
while((ch = getchar()) != EOF && isdigit(ch))
<BR> i = 10 * i + ch - 48; /* convert ASCII
into int value */ <BR>
<P> /* if non digit char was read, push it back into input
buffer */ <BR> if (ch != EOF)
<BR> ungetc(ch, stdin); <BR>
<P> printf("i = %d, next char in buffer = %c\n", i,
getchar()); <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函數(shù)名: ungetch <BR>功 能: 把一個字符退回到鍵盤緩沖區(qū)中 <BR>用 法: int
ungetch(int c); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <ctype.h> <BR>#include
<conio.h> <BR>
<P>int main( void ) <BR>{ <BR> int i=0; <BR> char
ch; <BR>
<P> puts("Input an integer followed by a char:"); <BR>
<P> /* read chars until non digit or EOF */ <BR>
while((ch = getche()) != EOF && isdigit(ch))
<BR> i = 10 * i + ch - 48; /* convert ASCII
into int value */ <BR>
<P> /* if non digit char was read, push it back into input
buffer */ <BR> if (ch != EOF)
<BR> ungetch(ch); <BR>
<P> printf("\n\ni = %d, next char in buffer = %c\n", i,
getch()); <BR> return 0; <BR>} <BR> <BR>
<BR> <BR>
<P>函數(shù)名: unixtodos <BR>功 能: 把日期和時間轉(zhuǎn)換成DOS格式 <BR>用 法: void
unixtodos(long utime, struct date *dateptr, <BR> struct time
*timeptr); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <dos.h> <BR>
<P>char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
<BR>
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; <BR>
<P>#define SECONDS_PER_DAY 86400L /* the number of seconds in one
day */ <BR>
<P>struct date dt; <BR>struct time tm; <BR>
<P>int main(void) <BR>{ <BR> unsigned long val; <BR>
<P>/* get today's date and time */ <BR> getdate(&dt);
<BR> gettime(&tm); <BR> printf("today is %d %s
%d\n", dt.da_day, month[dt.da_mon], dt.da_year); <BR>
<P>/* convert date and time to unix format (number of seconds since Jan 1,
1970 */ <BR> val = dostounix(&dt, &tm); <BR>/*
subtract 42 days worth of seconds */ <BR> val -=
(SECONDS_PER_DAY * 42); <BR>
<P>/* convert back to dos time and date */ <BR> unixtodos(val,
&dt, &tm); <BR> printf("42 days ago it was %d %s
%d\n", <BR> dt.da_day,
month[dt.da_mon], dt.da_year); <BR> return 0; <BR>} <BR>
<BR> <BR> <BR>
<P>函數(shù)名: unlink <BR>功 能: 刪掉一個文件 <BR>用 法: int unlink(char
*filename); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <io.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *fp = fopen("junk.jnk","w");
<BR> int status; <BR>
<P> fprintf(fp,"junk"); <BR>
<P> status = access("junk.jnk",0); <BR> if (status
== 0) <BR> printf("File exists\n");
<BR> else <BR> printf("File
doesn't exist\n"); <BR>
<P> fclose(fp); <BR> unlink("junk.jnk");
<BR> status = access("junk.jnk",0); <BR> if
(status == 0) <BR> printf("File exists\n");
<BR> else <BR> printf("File
doesn't exist\n"); <BR> <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函數(shù)名: unlock <BR>功 能: 解除文件共享鎖 <BR>用 法: int unlock(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> handle =
sopen("c:\\autoexec.bat",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>
<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/039.htm">后一頁</A><BR><A
href="http://www.hjflying.8u8.com/cl/037.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>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -