c语言后缀字母u和l如何使用,C语言函数大全(u开头)

本文详细介绍了C语言中以U字母开头的多个标准库函数,包括ultoa、ungetc、ungetch、unixtodos、unlink及unlock的功能、用法及示例程序。通过这些示例,读者可以了解如何将无符号长整型数转换为字符串、如何把字符退回到输入缓冲区、如何进行日期时间转换等实用操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

66c5a88b11a838ba5d16b803a5a9a10d.png

函数名: ultoa

功 能: 转换一个无符号长整型数为字符串

用 法: char *ultoa(unsigned long value, char *string, int radix);

程序例:

#include

#include

int main( void )

{

unsigned long lnumber = 3123456789L;

char string[25];

ultoa(lnumber,string,10);

printf("string = %s unsigned long = %lu\n",string,lnumber);

return 0;

}

函数名: ungetc

功 能: 把一个字符退回到输入流中

用 法: int ungetc(char c, FILE *stream);

程序例:

#include

#include

int main( void )

{

int i=0;

char ch;

puts("Input an integer followed by a char:");

/* read chars until non digit or EOF */

while((ch = getchar()) != EOF && isdigit(ch))

i = 10 * i + ch - 48; /* convert ASCII into int value */

/* if non digit char was read, push it back into input buffer */

if (ch != EOF)

ungetc(ch, stdin);

printf("i = %d, next char in buffer = %c\n", i, getchar());

return 0;

}

函数名: ungetch

功 能: 把一个字符退回到键盘缓冲区中

用 法: int ungetch(int c);

程序例:

#include

#include

#include

int main( void )

{

int i=0;

char ch;

puts("Input an integer followed by a char:");

/* read chars until non digit or EOF */

while((ch = getche()) != EOF && isdigit(ch))

i = 10 * i + ch - 48; /* convert ASCII into int value */

/* if non digit char was read, push it back into input buffer */

if (ch != EOF)

ungetch(ch);

printf("\n\ni = %d, next char in buffer = %c\n", i, getch());

return 0;

}

函数名: unixtodos

功 能: 把日期和时间转换成DOS格式

用 法: void unixtodos(long utime, struct date *dateptr,

struct time *timeptr);

程序例:

#include

#include

char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",

"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

#define SECONDS_PER_DAY 86400L /* the number of seconds in one day */

struct date dt;

struct time tm;

int main(void)

{

unsigned long val;

/* get today’s date and time */

getdate(&dt);

gettime(&tm);

printf("today is %d %s %d\n", dt.da_day, month[dt.da_mon], dt.da_year);

/* convert date and time to unix format (number of seconds since Jan 1, 1970 */

val = dostounix(&dt, &tm);

/* subtract 42 days worth of seconds */

val -= (SECONDS_PER_DAY * 42);

/* convert back to dos time and date */

unixtodos(val, &dt, &tm);

printf("42 days ago it was %d %s %d\n",

dt.da_day, month[dt.da_mon], dt.da_year);

return 0;

}

函数名: unlink

功 能: 删掉一个文件

用 法: int unlink(char *filename);

程序例:

#include

#include

int main(void)

{

FILE *fp = fopen("junk.jnk","w");

int status;

fprintf(fp,"junk");

status = access("junk.jnk",0);

if (status == 0)

printf("File exists\n");

else

printf("File doesn’t exist\n");

fclose(fp);

unlink("junk.jnk");

status = access("junk.jnk",0);

if (status == 0)

printf("File exists\n");

else

printf("File doesn’t exist\n");

return 0;

}

函数名: unlock

功 能: 解除文件共享锁

用 法: int unlock(int handle, long offset, long length);

程序例:

#include

#include

#include

#include

#include

#include

int main(void)

{

int handle, status;

long length;

handle = sopen("c:\\autoexec.bat",O_RDONLY,SH_DENYNO,S_IREAD);

if (handle < 0)

{

printf("sopen failed\n");

exit(1);

}

length = filelength(handle);

status = lock(handle,0L,length/2);

if (status == 0)

printf("lock succeeded\n");

else

printf("lock failed\n");

status = unlock(handle,0L,length/2);

if (status == 0)

printf("unlock succeeded\n");

else

printf("unlock failed\n");

close(handle);

return 0;

}

2829f2ca24f0d0090cbba57f30759f23.png

C语言函数大全(u开头).doc

下载Word文档到电脑,方便收藏和打印[全文共2005字]

编辑推荐:

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

8b95f2eb3d3f7ce4dc3bf1178c74941e.png

下载Word文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值