u.txt
资源名称:C.rar [点击查看]
上传用户:harvey99
上传日期:2020-01-11
资源大小:938k
文件大小:4k
源码类别:

其他书籍

开发平台:

CHM

  1.   返回>>C语言函数大全
  2. 函数名: ultoa 
  3. 功  能: 转换一个无符号长整型数为字符串
  4. 用  法: char *ultoa(unsigned long value, char *string, int radix);
  5. 程序例: 
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. int main( void )
  9. {
  10.    unsigned long lnumber = 3123456789L;
  11.    char string[25];
  12.    ultoa(lnumber,string,10);
  13.    printf("string = %s  unsigned long = %lun",string,lnumber);
  14.    return 0;
  15. }
  16.  
  17.  
  18.  
  19. 函数名: ungetc
  20. 功  能: 把一个字符退回到输入流中
  21. 用  法: int ungetc(char c, FILE *stream);
  22. 程序例:
  23. #include <stdio.h>
  24. #include <ctype.h>
  25. int main( void )
  26. {
  27.    int i=0;
  28.    char ch;
  29.    puts("Input an integer followed by a char:");
  30.    /* read chars until non digit or EOF */
  31.    while((ch = getchar()) != EOF && isdigit(ch))
  32.       i = 10 * i + ch - 48; /* convert ASCII into int value */
  33.    /* if non digit char was read, push it back into input buffer */
  34.    if (ch != EOF)
  35.       ungetc(ch, stdin);
  36.    printf("i = %d, next char in buffer = %cn", i, getchar());
  37.    return 0;
  38. }
  39.  
  40.  
  41.  
  42. 函数名: ungetch
  43. 功  能: 把一个字符退回到键盘缓冲区中
  44. 用  法: int ungetch(int c);
  45. 程序例:
  46. #include <stdio.h>
  47. #include <ctype.h>
  48. #include <conio.h>
  49. int main( void )
  50. {
  51.    int i=0;
  52.    char ch;
  53.    puts("Input an integer followed by a char:");
  54.    /* read chars until non digit or EOF */
  55.    while((ch = getche()) != EOF && isdigit(ch))
  56.       i = 10 * i + ch - 48; /* convert ASCII into int value */
  57.    /* if non digit char was read, push it back into input buffer */
  58.    if (ch != EOF)
  59.       ungetch(ch);
  60.    printf("nni = %d, next char in buffer = %cn", i, getch());
  61.    return 0;
  62. }
  63.  
  64.  
  65.  
  66. 函数名: unixtodos
  67. 功  能: 把日期和时间转换成DOS格式
  68. 用  法: void unixtodos(long utime, struct date *dateptr,
  69.    struct time *timeptr);
  70. 程序例:
  71. #include <stdio.h>
  72. #include <dos.h>
  73. char *month[] = {"---", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  74.                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  75. #define SECONDS_PER_DAY 86400L  /* the number of seconds in one day */
  76. struct date dt;
  77. struct time tm;
  78. int main(void)
  79. {
  80.    unsigned long val;
  81. /* get today's date and time */
  82.    getdate(&dt);
  83.    gettime(&tm);
  84.    printf("today is %d %s %dn", dt.da_day, month[dt.da_mon], dt.da_year);
  85. /* convert date and time to unix format (number of seconds since Jan 1, 1970 */
  86.    val = dostounix(&dt, &tm);
  87. /* subtract 42 days worth of seconds */
  88.    val -= (SECONDS_PER_DAY * 42);
  89. /* convert back to dos time and date */
  90.    unixtodos(val, &dt, &tm);
  91.    printf("42 days ago it was %d %s %dn",
  92.         dt.da_day, month[dt.da_mon], dt.da_year);
  93.    return 0;
  94. }
  95.  
  96.  
  97.  
  98. 函数名: unlink
  99. 功  能: 删掉一个文件
  100. 用  法: int unlink(char *filename);
  101. 程序例:
  102. #include <stdio.h>
  103. #include <io.h>
  104. int main(void)
  105. {
  106.    FILE *fp = fopen("junk.jnk","w");
  107.    int status;
  108.    fprintf(fp,"junk");
  109.    status = access("junk.jnk",0);
  110.    if (status == 0)
  111.       printf("File existsn");
  112.    else
  113.       printf("File doesn't existn");
  114.    fclose(fp);
  115.    unlink("junk.jnk");
  116.    status = access("junk.jnk",0);
  117.    if (status == 0)
  118.       printf("File existsn");
  119.    else
  120.       printf("File doesn't existn");
  121.  
  122.    return 0;
  123. }
  124.  
  125.  
  126.  
  127. 函数名: unlock
  128. 功  能: 解除文件共享锁
  129. 用  法: int unlock(int handle, long offset, long length);
  130. 程序例:
  131. #include <io.h>
  132. #include <fcntl.h>
  133. #include <sysstat.h>
  134. #include <process.h>
  135. #include <share.h>
  136. #include <stdio.h>
  137. int main(void)
  138. {
  139.    int handle, status;
  140.    long length;
  141.    handle = sopen("c:\autoexec.bat",O_RDONLY,SH_DENYNO,S_IREAD);
  142.    if (handle < 0)
  143.    {
  144.        printf("sopen failedn");
  145.        exit(1);
  146.    }
  147.    length = filelength(handle);
  148.    status = lock(handle,0L,length/2);
  149.    if (status == 0)
  150.       printf("lock succeededn");
  151.    else
  152.       printf("lock failedn");
  153.    status = unlock(handle,0L,length/2);
  154.    if (status == 0)
  155.       printf("unlock succeededn");
  156.    else
  157.       printf("unlock failedn");
  158.    close(handle);
  159.    return 0;
  160. }
  161.