韩冰 发表于 2004-10-4 02:54

函数大全(u开头)

<P><FONT color=#ff0000>函数名: ultoa </FONT>
功 能: 转换一个无符号长整型数为字符串
用 法: char *ultoa(unsigned long value, char *string, int radix);
程序例: </P>
<P><FONT color=#0000ff>#include <STDLIB.H>
#include <STDIO.H></FONT></P>
<P><FONT color=#0000ff>int main( void )
{
unsigned long lnumber = 3123456789L;
char string; </FONT></P>
<P><FONT color=#0000ff>ultoa(lnumber,string,10);
printf("string = %s unsigned long = %lu\n",string,lnumber); </FONT></P>
<P><FONT color=#0000ff>return 0;
}
</FONT>

</P>
<P><FONT color=#ff0000>函数名: ungetc </FONT>
功 能: 把一个字符退回到输入流中
用 法: int ungetc(char c, FILE *stream);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <CTYPE.H></FONT></P>
<P><FONT color=#0000ff>int main( void )
{
int i=0;
char ch; </FONT></P>
<P><FONT color=#0000ff>puts("Input an integer followed by a char:"); </FONT></P>
<P><FONT color=#0000ff>/* read chars until non digit or EOF */
while((ch = getchar()) != EOF &amp;&amp; isdigit(ch))
i = 10 * i + ch - 48; /* convert ASCII into int value */ </FONT></P>
<P><FONT color=#0000ff>/* if non digit char was read, push it back into input buffer */
if (ch != EOF)
ungetc(ch, stdin); </FONT></P>
<P><FONT color=#0000ff>printf("i = %d, next char in buffer = %c\n", i, getchar());
return 0;
} </FONT>


</P>
<P><FONT color=#ff0000>函数名: ungetch </FONT>
功 能: 把一个字符退回到键盘缓冲区中
用 法: int ungetch(int c);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <CTYPE.H>
#include <CONIO.H></FONT></P>
<P><FONT color=#0000ff>int main( void )
{
int i=0;
char ch; </FONT></P>
<P><FONT color=#0000ff>puts("Input an integer followed by a char:"); </FONT></P>
<P><FONT color=#0000ff>/* read chars until non digit or EOF */
while((ch = getche()) != EOF &amp;&amp; isdigit(ch))
i = 10 * i + ch - 48; /* convert ASCII into int value */ </FONT></P>
<P><FONT color=#0000ff>/* if non digit char was read, push it back into input buffer */
if (ch != EOF)
ungetch(ch); </FONT></P>
<P><FONT color=#0000ff>printf("\n\ni = %d, next char in buffer = %c\n", i, getch());
return 0;
}


</FONT></P>
<P><FONT color=#ff0000>函数名: unixtodos </FONT>
功 能: 把日期和时间转换成DOS格式
用 法: void unixtodos(long utime, struct date *dateptr,
struct time *timeptr);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <DOS.H></FONT></P>
<P><FONT color=#0000ff>char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; </FONT></P>
<P><FONT color=#0000ff>#define SECONDS_PER_DAY 86400L /* the number of seconds in one day */ </FONT></P>
<P><FONT color=#0000ff>struct date dt;
struct time tm; </FONT></P>
<P><FONT color=#0000ff>int main(void)
{
unsigned long val; </FONT></P>
<P><FONT color=#0000ff>/* get today's date and time */
getdate(&amp;dt);
gettime(&amp;tm);
printf("today is %d %s %d\n", dt.da_day, month, dt.da_year); </FONT></P>
<P><FONT color=#0000ff>/* convert date and time to unix format (number of seconds since Jan 1, 1970 */
val = dostounix(&amp;dt, &amp;tm);
/* subtract 42 days worth of seconds */
val -= (SECONDS_PER_DAY * 42); </FONT></P>
<P><FONT color=#0000ff>/* convert back to dos time and date */
unixtodos(val, &amp;dt, &amp;tm);
printf("42 days ago it was %d %s %d\n",
dt.da_day, month, dt.da_year);
return 0;
}


</FONT></P>
<P><FONT color=#ff0000>函数名: unlink </FONT>
功 能: 删掉一个文件
用 法: int unlink(char *filename);
程序例: </P>
<P><FONT color=#0000ff>#include <STDIO.H>
#include <IO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
FILE *fp = fopen("junk.jnk","w");
int status; </FONT></P>
<P><FONT color=#0000ff>fprintf(fp,"junk"); </FONT></P>
<P><FONT color=#0000ff>status = access("junk.jnk",0);
if (status == 0)
printf("File exists\n");
else
printf("File doesn't exist\n"); </FONT></P>
<P><FONT color=#0000ff>fclose(fp);
unlink("junk.jnk");
status = access("junk.jnk",0);
if (status == 0)
printf("File exists\n");
else
printf("File doesn't exist\n");
</FONT></P>
<P><FONT color=#0000ff>return 0;
}

</FONT>
</P>
<P><FONT color=#0000ff>函数名: unlock </FONT>
功 能: 解除文件共享锁
用 法: int unlock(int handle, long offset, long length);
程序例: </P>
<P><FONT color=#0000ff>#include <IO.H>
#include <FCNTL.H>
#include <SYS\STAT.H>
#include <PROCESS.H>
#include <SHARE.H>
#include <STDIO.H></FONT></P>
<P><FONT color=#0000ff>int main(void)
{
int handle, status;
long length; </FONT></P>
<P><FONT color=#0000ff>handle = sopen("c:\\autoexec.bat",O_RDONLY,SH_DENYNO,S_IREAD); </FONT></P>
<P><FONT color=#0000ff>if (handle &lt; 0)
{
printf("sopen failed\n");
exit(1);
} </FONT></P>
<P><FONT color=#0000ff>length = filelength(handle);
status = lock(handle,0L,length/2); </FONT></P>
<P><FONT color=#0000ff>if (status == 0)
printf("lock succeeded\n");
else
printf("lock failed\n"); </FONT></P>
<P><FONT color=#0000ff>status = unlock(handle,0L,length/2); </FONT></P>
<P><FONT color=#0000ff>if (status == 0)
printf("unlock succeeded\n");
else
printf("unlock failed\n"); </FONT></P>
<P><FONT color=#0000ff>close(handle);
return 0;
} </FONT></P>
页: [1]
查看完整版本: 函数大全(u开头)