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

函数声明 | 函数功能 |
|---|---|
| 异常终止一个进程 |
| 求整数的绝对值 |
| 从drive指定的驱动器磁盘上,sectno指定的逻辑扇区号开始读取nsects个(最多64K个)扇区的内容,储存于buffer所指的缓冲区中。 |
| 将指定内容写入磁盘上的指定扇区 |
| 确定文件的访问权限 |
| 反余弦函数 |
| 分配DOS存储段 |
| 画一弧线 |
| 转换日期和时间为ASCII码 |
| 反正弦函数 |
| 测试一个条件并可能使程序终止 |
| 反正切函数 |
| 计算Y/X的反正切值 |
| 注册终止函数 |
| 把字符串转换成浮点数 |
| 把字符串转换成整型数 |
| 把字符串转换成长整型数 |
函数声明 | 函数功能 |
|---|---|
| 异常终止一个进程 |
注意:
abort()函数用于终止当前程序的执行。当程序调用abort()函数时,它会立即退出,并生成一个错误信号,通知操作系统程序非正常终止。如果程序已经打开了一些文件或句柄,但尚未关闭它们,则这些资源可能无法被正确释放。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Calling abort()\n");
abort();
printf("already abort()"); // 这里永远也到不了
return 0;
}
函数声明 | 函数功能 |
|---|---|
| 求整数的绝对值 |
#include <stdio.h>
#include <math.h>
int main(void)
{
int number = -666;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
函数声明 | 函数功能 |
|---|---|
| 从drive指定的驱动器磁盘上,sectno指定的逻辑扇区号开始读取nsects个(最多64K个)扇区的内容,储存于buffer所指的缓冲区中。 |
#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 驱动器读取一个扇区的数据,并将其中一些字符输出到屏幕上。
注意: 程序中使用了一些
DOS特定的函数,比如absread()和getch(),可能不适用于其他操作系统或编译器环境。
函数声明 | 函数功能 |
|---|---|
| 将指定内容写入磁盘上的指定扇区 |
#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 和标准输入输出函数。
函数声明 | 函数功能 |
|---|---|
| 确定文件的访问权限 |
#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);
}

函数声明 | 函数功能 |
|---|---|
| 反余弦函数 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 分配DOS存储段 |
#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,并打印出已分配内存的段地址;函数声明 | 函数功能 |
|---|---|
| 画一弧线 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 转换日期和时间为ASCII码 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 反正弦函数 |
#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);
}
函数声明 | 函数功能 |
|---|---|
| 测试一个条件并可能使程序终止 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 反正切函数 |
#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);
}
函数声明 | 函数功能 |
|---|---|
| 计算Y/X的反正切值 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 注册终止函数 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 把字符串转换成浮点数 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 把字符串转换成整型数 |
#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;
}
函数声明 | 函数功能 |
|---|---|
| 把字符串转换成长整型数 |
#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);
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
