C语言函数大全(u开头)
函数名:ultoa
函数:将无符号长整型转换为字符串
用法:char * ul toa(无符号长整型值,char * string,int radix);
程序示例:
# include
# include
int main(void)
{
无符号长整型数= 3123456789L
char字符串[25];
ultoa(lnumber,string,10);
printf(" string = % s unsigned long = % Lu \ n ",string,lnumber);
返回0;
}
函数名:ungetc
函数:向输入流返回一个字符
用法:intungtec (char c,file * stream);
程序示例:
# include
# include
int main(void)
{
int I = 0;
char ch;
puts("输入一个整数后跟一个char:");
/*读取字符直到非数字或EOF */
while((ch = getchar())!= EOF & & is digit(ch))
I = 10 * I+ch-48;/*将ASCII转换为int值*/
/*如果读取了非数字字符,则将其推回到输入缓冲区*/
if (ch!= EOF)
ungetc(ch,stdin);
printf("i = %d,buffer中的下一个字符= %c\n ",I,getchar());
返回0;
}
函数名:ungetch
函数:向键盘缓冲区返回一个字符
用法:int un getch(int c);
程序示例:
# include
# include
# int main(void)
{
int I = 0;
char ch;
puts("输入一个整数后跟一个char:");
/*读取字符直到非数字或EOF */
while((ch = getche())!= EOF & & is digit(ch))
I = 10 * I+ch-48;/*将ASCII转换为int值*/
/*如果读取了非数字字符,则将其推回到输入缓冲区*/
if (ch!= EOF)
un getch(ch);
printf("\n\ni = %d,buffer中的下一个字符= %c\n ",I,getch());
返回0;
}
函数名:unixtodos
函数:将日期和时间转换为dos格式
用法:void UNIX todos (long utime,struct date * dateptr,
struct time * time ptr);
程序示例:
# include
# include
char * month[]= { "-"、" Jan "、" Feb "、" Mar "、" Apr "、" May "、" "
# define SECONDS _ PER _ DAY 86400 l/*一天中的秒数*/
struct date dt;
结构时间TM;
int main(void)
{
无符号long val
/*获取今天的日期和时间*/
getdate(& dt);
gettime(& TM);
printf("今天是%d %s %d\n ",dt.da_day,month[dt.da_mon],dt . da _ year);
/*将日期和时间转换为unix格式(自1970年1月1日以来的秒数*/
val = dostounix(&dt,& TM);
/*减去42天的秒*/
val-=(SECONDS _ PER _ DAY * 42);
/*转换回dos时间和日期*/
unixtodos(val,&dt,& TM);
printf("42天前是%d %s %d\n ",
dt.da_day,month[dt.da_mon],dt . da _ year);
返回0;
}
函数名:unlink
函数:删除一个文件
用法:int unlink(char * filename);
程序示例:
# include
# include
int main(void)
{
file * FP = fopen(" junk . JNK "," W ");
int状态;
fprintf(fp,“垃圾”);
status = access("junk.jnk ",0);
if(status = = 0)
printf("文件存在\ n ");
else
printf("文件不存在\ n ");
f close(FP);
unlink(" junk . JNK ");
status = access("junk.jnk ",0);
if(status = = 0)
printf("文件存在\ n ");
else
printf("文件不存在\ n ");
返回0;
}
函数名:unlock
函数:解锁文件共享
用法:int unlock (int handle,long offset,long length);
程序示例:
# include
# include
# include
# include
# include
int main(void)[
long length;
handle = sopen(" c:\ \ autoexec . bat ",O_RDONLY,SH_DENYNO,S _ IREAD);
if(handle < 0)
{
printf(" sopen failed \ n ");
退出(1);
}
length = file length(handle);
status = lock(handle,0L,length/2);
if(status = = 0)
printf("锁定成功\ n ");
else
printf("锁定失败\ n ");
status = unlock(手柄,0L,长度/2);
if(status = = 0)
printf("解锁成功\ n ");
else
printf("解锁失败\ n ");
关闭(句柄);
返回0;
}
0条评论