首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >C语言函数大全--a开头的函数

C语言函数大全--a开头的函数

原创
作者头像
huazie
修改于 2024-12-01 09:54:35
修改于 2024-12-01 09:54:35
5060
举报
文章被收录于专栏:开发语言-C/C++开发语言-C/C++

开始之前,引用一篇《基于Redis海量数据场景分布式ID架构实践》,该文通过比对不同实现方案的优缺点,帮助大家在分布式ID生成方面提供一些有益的参考和启示。有需要的朋友可以深入研究下!

总览

函数声明

函数功能

void abort(void);

异常终止一个进程

int abs(int i);

求整数的绝对值

int absread(int drive, int nsects, int sectno, void *buffer);

从drive指定的驱动器磁盘上,sectno指定的逻辑扇区号开始读取nsects个(最多64K个)扇区的内容,储存于buffer所指的缓冲区中。

int abswrite(int drive, int nsects, int sectno, void *buffer);

将指定内容写入磁盘上的指定扇区

int access(const char *filename, int amode);

确定文件的访问权限

double acos(double x);

反余弦函数

int allocmem(unsigned size, unsigned *seg);

分配DOS存储段

void arc(int x, int y, int stangle, int endangle, int radius);

画一弧线

char *asctime(const struct tm *tblock);

转换日期和时间为ASCII码

double asin(double x);

反正弦函数

void assert(int test);

测试一个条件并可能使程序终止

double atan(double x);

反正切函数

double atan2(double y, double x);

计算Y/X的反正切值

int atexit(atexit_t func);

注册终止函数

double atof(const char *nptr);

把字符串转换成浮点数

int atoi(const char *nptr);

把字符串转换成整型数

long atol(const char *nptr);

把字符串转换成长整型数

1. abort

1.1 函数说明

函数声明

函数功能

void abort(void);

异常终止一个进程

注意: abort() 函数用于终止当前程序的执行。当程序调用 abort() 函数时,它会立即退出,并生成一个错误信号,通知操作系统程序非正常终止。如果程序已经打开了一些文件或句柄,但尚未关闭它们,则这些资源可能无法被正确释放。

1.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    printf("Calling abort()\n");
    abort();
    printf("already abort()"); // 这里永远也到不了
    return 0; 
}

1.3 运行结果

2. abs

2.1 函数说明

函数声明

函数功能

int abs(int i);

求整数的绝对值

2.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <math.h>

int main(void)
{
    int number = -666;
  	printf("number: %d  absolute value: %d\n", number, 	abs(number));
  	return 0;
}

2.3 运行结果

3. absread

3.1 函数说明

函数声明

函数功能

int absread(int drive, int nsects, int sectno, void *buffer);

从drive指定的驱动器磁盘上,sectno指定的逻辑扇区号开始读取nsects个(最多64K个)扇区的内容,储存于buffer所指的缓冲区中。

3.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dos.h>

int main(void)
{
  	int i, strt, ch_out, sector;
  	char buf[512];

  	printf("Insert a diskette into drive A and press any key\n");
  	getch();
  	sector = 0;
  	if (absread(0, 1, sector, &buf) != 0)
  	{
     	perror("Disk problem");
     	exit(1);
  	}
  	printf("Read OK\n");
  	strt = 3;
  	for (i=0; i<80; i++)
  	{
     	ch_out = buf[strt+i];
     	putchar(ch_out);
  	}
  	printf("\n");
  	return(0);
}

上述的代码实现了从 A 驱动器读取一个扇区的数据,并将其中一些字符输出到屏幕上。

  • 首先提示用户插入一个软盘到 A 驱动器中。
  • 然后读取 A 驱动器上第 0 个扇区的数据到缓冲区 buf 中。
  • 接着检查读取是否成功。如果不成功,输出错误信息并退出程序。
  • 最后将 buf 缓冲区中偏移量为 3 到偏移量为 82 的字符依次输出到屏幕上。

注意: 程序中使用了一些 DOS 特定的函数,比如 absread()getch(),可能不适用于其他操作系统或编译器环境。

4. abswrite

4.1 函数说明

函数声明

函数功能

int abswrite(int drive, int nsects, int sectno, void *buffer);

将指定内容写入磁盘上的指定扇区

4.2 演示示例

代码语言:c
AI代码解释
复制
#include <dos.h>
#include <stdio.h>

unsigned char buff[512];

int main()
{
    int i;
    char c;
    printf("\nQuick Format 1.44MB\n");
    printf("Program by ChenQingyang.\n");
    printf("ALL DATA IN THE FLOPPY DISK WILL BE LOST!!\n");
    printf("\nInsert a diskette for drive A:\n");
    printf("and press ENTER when ready. . .");
    c=getchar();
    printf("\n\nCleaning FAT area. . .");
    buff[0]=0xf0;
    buff[1]=buff[2]=0xff;
    for (i=3;i<512;i++) 
        buff[i]=0;
    abswrite(0,1,1,buff);
    abswrite(0,1,10,buff);
    for (i=0;i<512;i++) 
        buff[i]=0;
    for (i=2;i<10;i++) 
        abswrite (0,1,i,buff);
    for (i=11;i<19;i++) 
        abswrite (0,1,i,buff);
    printf("\nCleaning ROOT area. . .");
    for (i=19;i<33;i++) 
        abswrite (0,1,i,buff);
    printf("\n\nQuickFormat Completed!\n");
}

上述代码是一个使用 DOS 命令格式化软盘的程序。它会提示用户输入软盘,然后清空软盘的FAT和根目录区域,并在完成后打印 “QuickFormat Completed!” 的信息。程序使用了 <dos.h><stdio.h> 头文件,其中包含了一些 DOS 和标准输入输出函数。

5. access

5.1 函数说明

函数声明

函数功能

int access(const char *filename, int amode);

确定文件的访问权限

5.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <io.h>

int file_exists(char *filename);

int main(void)
{
    printf("Does students1.txt exist: %s\n",
    file_exists("students1.txt") ? "YES" : "NO");
    return 0;
}

int file_exists(char *filename)
{
    return (access(filename, 0) == 0);
}

5.3 运行结果

6. acos

6.1 函数说明

函数声明

函数功能

double acos(double x);

反余弦函数

6.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <math.h>

int main(void)
{
    double result;
    double x = 0.5;

    result = acos(x); 
    printf("The arc cosine of %lf is %lf\n", x, result);
    return 0;
}

6.3 运行结果

7. allocmem

7.1 函数说明

函数声明

函数功能

int allocmem(unsigned size, unsigned *seg);

分配DOS存储段

7.2 演示示例

代码语言:c
AI代码解释
复制
#include <dos.h>
#include <alloc.h>
#include <stdio.h>

int main(void)
{
    unsigned int size, segp;
    int stat;
    size = 64; /* (64 x 16) = 1024 bytes */
    stat = allocmem(size, &segp);
    if (stat == -1)
        printf("Allocated memory at segment: %x\n", segp);
    else
        printf("Failed: maximum number of paragraphs available is %u\n",stat);
    return 0;
}

在上述的示例代码,

  • 首先调用了 allocmem() 函数来分配内存,其中传递了两个参数:size 表示请求的内存大小(以段为单位),这里设置为 64 段;&segp 表示返回的内存段地址将存储在此变量中。
  • 如果成功分配内存,allocmem()函数将返回 -1,并打印出已分配内存的段地址;
  • 否则,它将返回最大可用段数,并打印出失败的消息。

8. arc

8.1 函数说明

函数声明

函数功能

void arc(int x, int y, int stangle, int endangle, int radius);

画一弧线

8.2 演示示例

代码语言:c
AI代码解释
复制
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;

    int midx, midy;
    int stangle = 45, endangle = 135;
    int radius = 100;

    /* initialize graphics and local variables */
    char ch[] = "";
    initgraph(&gdriver, &gmode, ch);

    /* read result of initialization */
    errorcode = graphresult();    /* an error occurred */
    if (errorcode != grOk)
    {
        printf("Graphics error: %s\n", grapherrormsg(errorcode));
        printf("Press any key to halt:");
        getch();
        exit(1);    /* terminate with an error code */
    }

    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    setcolor(getmaxcolor());

    /* draw arc */
    arc(midx, midy, stangle, endangle, radius);

    /* clean up */
    getch();
    closegraph();
    return 0;
}

8.3 运行结果

9. asctime

9.1 函数说明

函数声明

函数功能

char *asctime(const struct tm *tblock);

转换日期和时间为ASCII码

9.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <string.h>
#include <time.h>

int main(void)
{
    struct tm t;
    char str[80];

    /* sample loading of tm structure  */

    t.tm_sec    = 1;  /* Seconds */
    t.tm_min    = 30; /* Minutes */
    t.tm_hour   = 9;  /* Hour */
    t.tm_mday   = 22; /* Day of the Month  */
    t.tm_mon    = 11; /* Month */
    t.tm_year   = 56; /* Year - does not include century */
    t.tm_wday   = 4;  /* Day of the week  */
    t.tm_yday   = 0;  /* Does not show in asctime  */
    t.tm_isdst  = 0;  /* Is Daylight SavTime; does not show in asctime */

    /* converts structure to null terminated
    string */

    strcpy(str, asctime(&t));
    printf("%s\n", str);

    return 0;
}

9.3 运行结果

10. asin

10.1 函数说明

函数声明

函数功能

double asin(double x);

反正弦函数

10.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <math.h>

int main(void)
{
    double result;
    double x = 0.5;

    result = asin(x);
    printf("The arc sin of %lf is %lf\n", x, result);
    return(0);
}

10.3 运行结果

11. assert

11.1 函数说明

函数声明

函数功能

void assert(int test);

测试一个条件并可能使程序终止

11.2 演示示例

代码语言:c
AI代码解释
复制
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

struct ITEM {
   int key;
   int value;
};

/* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
    assert(itemptr != NULL);
   /* add item to list */
}

int main(void)
{
    additem(NULL);
    return 0;
}

11.3 运行结果

12. atan

12.1 函数说明

函数声明

函数功能

double atan(double x);

反正切函数

12.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <math.h>

int main(void)
{
    double result;
    double x = 0.5;

    result = atan(x);
    printf("The arc tangent of %lf is %lf\n", x, result);
    return(0);
}

12.3 运行结果

13. atan2

13.1 函数说明

函数声明

函数功能

double atan2(double y, double x);

计算Y/X的反正切值

13.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <math.h>

int main(void)
{
	double result;
	double x = 60.0, y = 30.0;

	result = atan2(y, x);
	printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);
	return 0;
}

13.3 运行结果

14. atexit

14.1 函数说明

函数声明

函数功能

int atexit(atexit_t func);

注册终止函数

14.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdio.h>
#include <stdlib.h>

void exit_fn1(void)
{
    printf("Exit function #1 called\n");
}

void exit_fn2(void)
{
    printf("Exit function #2 called\n");
}

int main(void)
{
    /* post exit function #1 */
    atexit(exit_fn1);
    /* post exit function #2 */
    atexit(exit_fn2);
    return 0;
}

14.3 运行结果

15. atof

15.1 函数说明

函数声明

函数功能

double atof(const char *nptr);

把字符串转换成浮点数

15.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    float f;
    char *str = "1234.5678";

    f = atof(str);
    printf("string = %s float = %f\n", str, f);
    return 0;
}

15.3 运行结果

16. atoi

16.1 函数说明

函数声明

函数功能

int atoi(const char *nptr);

把字符串转换成整型数

16.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    int n;
    char *str = "1234.5678";

    n = atoi(str);
    printf("string = %s integer = %d\n", str, n);
    return 0;
}

16.3 运行结果

17. atol

17.1 函数说明

函数声明

函数功能

long atol(const char *nptr);

把字符串转换成长整型数

17.2 演示示例

代码语言:c
AI代码解释
复制
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    long l;
    char *lstr = "87654321";

    l = atol(lstr);
    printf("string = %s integer = %ld\n", lstr, l);
    return(0);
}

17.3 运行结果

参考

  1. [API Reference Document]

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
C语言函数大全--b开头的函数
开始之前,引用一篇《教你自创工作流,赋予AI助理个性化推荐超能力》,该文深入探讨了Spring AI及其在国内版本Spring AI Alibaba的实战应用,重点关注了如何构建一个功能丰富、智能高效的AI助理。有需要的朋友可以研究研究!
huazie
2024/12/06
4520
C语言函数大全--b开头的函数
C语言函数大全--i开头的函数
从指定 I/O 端口读取到的 16 位数据。若读取过程中出现错误,返回值的具体情况可能因系统和硬件而异。
huazie
2025/04/20
2960
C语言函数大全--i开头的函数
C语言函数大全--s 开头的函数(1)
注意:如果 n 超过了可表示的范围,或者结果溢出,则函数可能返回正无穷大、负无穷大或 NaN。
huazie
2025/07/06
1710
C语言函数大全--s 开头的函数(1)
C语言函数大全--h开头的函数
上述程序是一个基于DOS环境的磁盘错误处理示例。在磁盘操作出现错误时,向用户显示具体的错误消息,并提供 “中止”、“重试” 和 “忽略” 三种处理选项,根据用户的选择进行相应的处理。
huazie
2025/04/02
3350
C语言函数大全--h开头的函数
C语言函数大全--e开头的函数
以 (x, y) 为中心,xradius、yradius 为 x 轴 和 y 轴 半径,从角 stangle 开始,endangle 结束,画一段椭圆线。当stangle=0,endangle=360 时,画出一个完整的椭圆
huazie
2025/01/09
3990
C语言函数大全--e开头的函数
C语言函数大全--c开头的函数
huazie
2024/12/28
7360
C语言函数大全--c开头的函数
C语言函数大全--t 开头的函数
注意:tell() 函数和 lseek 函数的功能类似,但有一个重要的区别:tell() 函数只用于查询当前位置,而不能修改文件指针的位置。如果要修改文件指针的位置,请使用 lseek() 函数。
huazie
2025/07/08
1810
C语言函数大全--t 开头的函数
C语言函数大全--f开头的函数(上)
注意: 如果文件中的一行,不足 n-1 个字符,则读完该行就直接结束。如若该行(包括最后一个换行符)的字符数超过 n-1,则 fgets 只返回一个不完整的行,但是,缓冲区总是以 NULL 字符结尾,对 fgets 的下一次调用会继续读该行。函数成功将返回 stream,失败或读到文件结尾返回 NULL。因此不能直接通过 fgets 的返回值来判断函数是否是出错而终止的,应该借助 feof 函数或者 ferror 函数来判断。
huazie
2025/01/17
4150
C语言函数大全--f开头的函数(上)
C语言函数大全--r 开头的函数
每次调用它时会返回一个介于 0 和 RAND_MAX 之间的伪随机整数。其中,RAND_MAX 是一个常量,表示返回值的最大值,通常为 32767。
huazie
2025/07/01
1920
C语言函数大全--r 开头的函数
C语言函数大全--f开头的函数(下)
如果文件顺利打开后,指向该流的文件指针就会被返回;否则文件打开失败则返回 NULL,并把错误代码存在 error 中。
huazie
2025/01/18
3830
C语言函数大全--f开头的函数(下)
C语言函数大全--l开头的函数
上述示例程序中,首先通过 open() 函数打开一个名为 test.txt 的文件,并设置文件访问模式为可读写。接着,调用 lock() 函数对该文件进行加锁操作,保护写入数据的过程。然后,通过 write() 函数将数据写入到文件中。最后,调用 lock() 函数对该文件进行解锁操作,释放锁定的资源。
huazie
2025/04/29
2640
C语言函数大全--l开头的函数
C语言函数大全--g开头的函数(上)
上述代码是一个简单的图形程序,使用了图形库函数 arc 来绘制一个弧线并显示其起始和结束点的坐标。
huazie
2025/01/22
3900
C语言函数大全--g开头的函数(上)
C语言函数大全--s 开头的函数(2)
·注意: setmem() 并不是标准 C 函数,而是 POSIX 标准库函数,因此可能并不被所有平台所支持。如果您的编译器或操作系统不支持 setmem() 函数,可以使用标准 C 库函数 memset() 来代替
huazie
2025/07/06
2000
C语言函数大全--s 开头的函数(2)
C语言函数大全--c开头的函数之复数篇
相位角是描述波形在时间轴上的位置的一个重要参数,它决定了波形的起始位置和变化状态。在实际应用中,相位角的测量和控制对于电路设计和信号处理至关重要。通过对相位角的理解和应用,可以更好地分析和控制波动现象,从而实现对电力系统和通信系统的优化。
huazie
2024/12/29
3610
C语言函数大全--c开头的函数之复数篇
C语言函数大全--p 开头的函数
在上述的示例中,主线程调用了 pthread_create() 函数来创建一个新的线程,并传递一个函数指针 thread_func 作为新线程的入口点。新线程运行这个函数,并输出一条消息。主线程等待新线程结束,然后继续运行自己的代码。
huazie
2025/05/15
2980
C语言函数大全--p 开头的函数
C语言函数大全--s 开头的函数(3)
在使用 sleep() 函数时,将会使当前线程或者进程暂停指定的时间,以便给其他进程或线程执行机会,同时也可以用来控制程序的运行速度。
huazie
2025/07/08
1840
C语言函数大全--s 开头的函数(3)
C语言函数大全--m 开头的函数(下)
上述的示例代码,演示了如何使用 mmap() 函数将一个文件映射到内存中,并使用指针 ptr 访问这个映射区域 :
huazie
2025/05/10
3160
C语言函数大全--m 开头的函数(下)
C语言函数大全--n 开头的函数
huazie
2025/05/12
3970
C语言函数大全--n 开头的函数
C语言函数大全--d开头的函数
注意: 这个程序可能无法在现代操作系统上直接运行,因为其中的一些函数(如disable()、enable()、getvect() 和 setvect())是特定于 DOS 的。如果你想在现代操作系统(如 Linux 或 Windows)上运行这个程序,你可能需要使用更现代的方法来处理中断或使用 DOS 模拟器。
huazie
2025/01/05
3800
C语言函数大全--d开头的函数
C语言函数大全--w 开头的函数(1)
注意: 在使用 wcscat() 函数时,需要确保目标字符串 dest 的空间足够大,以容纳源字符串 src 的所有字符和一个结束符(\0)。如果目标字符串的空间不足,可能会导致数据覆盖和未定义行为。
huazie
2025/07/22
1750
C语言函数大全--w 开头的函数(1)
推荐阅读
相关推荐
C语言函数大全--b开头的函数
更多 >
交个朋友
加入腾讯云官网粉丝站
双11活动抢先看 更有社群专属礼券掉落
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档