C language library function (U letter)

xiaoxiao2021-03-06  44

Function name: Ultoa

Function: Convert an unsigned long integer to string

Usage: Char * Ultoa (unsigned long value, char * string, int RADIX);

Example:

#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;

}

Function name: ungetc

Function: Back a character back to the input stream

Usage: int UNGETC (Char C, File * stream);

Example:

#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;

}

Function name: ungetch

Function: Return a character to the keyboard buffer

Usage: int UNGETCH (INT C);

Example:

#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;

}

Function Name: Unixtodos

Function: Convert the date and time into a DOS format

Usage: void unixtodos (long utime, struct date * dateptr,

Struct Time * TimePtr);

Example:

#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 TimeTM;

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 day west of seconds * /

VAL - = (Seconds_Per_Day * 42);

/ * Convert Back to dos Time and Date * /

UNIXTODOS (VAL, & DT, & TM);

Printf ("42 days ago it is% D% S% D / N",

DT.DA_DAY, MONTH [DT.DA_MON], DT.DA_YEAR);

Return 0;

}

Function name: unlink

Function: Delete a file

Usage: int UNLINK (Char * filename);

Example:

#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;

}

Function Name: Unlock

Function: Release file sharing lock

Usage: int UNLOCK (Int Handle, Long Offset, Long Length);

Example:

#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;

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 successmeded / n");

Else

Printf ("Unlock Failed / N");

Close (Handle);

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-74422.html

New Post(0)