📄 038.htm
字号:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><TITLE>王大刚-->C语言编程宝典-->U</TITLE>
<META NAME="keywords" CONTENT="王大刚 C语言编程宝典 U">
<META NAME="description" CONTENT="王大刚 - C语言编程宝典 - U">
<style>
<!--
#page {position:absolute; z-index:0; left:0px; top:0px}
.tt3 {font: 9pt/12pt "宋体"}
.tt2 {font: 12pt/15pt "宋体"}
a {text-decoration:none}
a:hover {color: blue;text-decoration:underline}
-->
</style>
</HEAD>
<body text="#000000" aLink=#9900ff link=#006699 vLink=#006699 bgcolor="#FFFFFF" leftmargin="3" topmargin="3" marginheight="3" marginwidth="3">
<TABLE WIDTH="100%" CELLPADDING=10 CELLSPACING=0 BORDER=0>
<TR>
<TD CLASS="tt3" VALIGN="top" width="8%" bgcolor="#e0e0e0"><strong><A HREF="039.htm">后一页</A><BR>
<A HREF="037.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
<TD class="tt2" bgcolor="#F5F8F8" width="84%"><center><B><FONT style="FONT-SIZE: 16.5pt" COLOR="#FF6666" FACE="楷体_GB2312">U</FONT></B></center>
<hr color="#EE9B73" size="1" width="94%">
<BR>
<P>函数名: ultoa
<BR>功 能: 转换一个无符号长整型数为字符串
<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>函数名: 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>函数名: ungetch
<BR>功 能: 把一个字符退回到键盘缓冲区中
<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>函数名: unixtodos
<BR>功 能: 把日期和时间转换成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>函数名: 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>函数名: 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 color="#EE9B73" size="1" width="94%">
</TD>
<TD CLASS="tt3" VALIGN="bottom" width="8%" bgcolor="#e0e0e0"><strong><A HREF="039.htm">后一页</A><BR>
<A HREF="037.htm">前一页</A><BR>
<A HREF="index.html">回目录</A><BR>
<A HREF="../../../../index.htm">回首页</A><BR>
</strong>
</TD>
</TR>
</table>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -