c语言的库函数

article/2025/6/8 19:22:11

一、标准C库函数(15个)

二、数学函数

  • 用于求幂,计算平方跟,求绝对值。
  • #include <math.h>
  • 绝对值函数用于表达式的结构转换为非负函数

int x=-3;
printf("|%d|=%d\n",x,abs(x));

三、字符串处理函数

四、字符处理函数

五、转换函数和存储管理函数

六、随机函数

产生1~10的数:int i = rand()%10+1;或int n= rand()%11

七、日期和时间处理函数

struct tm{int tm_sec;  //   目前秒数,正常范围0~59,但允许至61秒int tm_min;  //   目前分数,范围0~59int tm_hour; //   午夜算起的时数,范围为0~23int tm_mday; //    目前月份的日数,范围01~31int tm_mon;  //    目前月份,从一月算起,范围0~11  int tm_year; //     从1900年算起至今的年审int tm_wday; //     一星期的日数,从星期一算起,范围0~6int tm_yday; //     从今年1月1日算起至今天的天数,范围为0~365}

/***
*time.h - definitions/declarations for time routines
*
*       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
*
*Purpose:
*       This file has declarations of time routines and defines
*       the structure returned by the localtime and gmtime routines and
*       used by asctime.
*       [ANSI/System V]
*
*       [Public]
*
****/#if     _MSC_VER > 1000
#pragma once
#endif#ifndef _INC_TIME
#define _INC_TIME#if     !defined(_WIN32) && !defined(_MAC)
#error ERROR: Only Mac or Win32 targets supported!
#endif#ifdef  _MSC_VER
/** Currently, all MS C compilers for Win32 platforms default to 8 byte* alignment.*/
#pragma pack(push,8)
#endif  /* _MSC_VER */#ifdef  __cplusplus
extern "C" {
#endif/* Define _CRTIMP */#ifndef _CRTIMP
#ifdef  _DLL
#define _CRTIMP __declspec(dllimport)
#else   /* ndef _DLL */
#define _CRTIMP
#endif  /* _DLL */
#endif  /* _CRTIMP *//* Define __cdecl for non-Microsoft compilers */#if     ( !defined(_MSC_VER) && !defined(__cdecl) )
#define __cdecl
#endif/* Define _CRTAPI1 (for compatibility with the NT SDK) */#ifndef _CRTAPI1
#if	_MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif#ifndef _MAC
#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif
#endif  /* ndef _MAC *//* Define the implementation defined time type */#ifndef _TIME_T_DEFINED
typedef long time_t;        /* time value */
#define _TIME_T_DEFINED     /* avoid multiple def's of time_t */
#endif#ifndef _CLOCK_T_DEFINED
typedef long clock_t;
#define _CLOCK_T_DEFINED
#endif#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif/* Define NULL pointer value */#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif#ifndef _TM_DEFINED
struct tm {int tm_sec;     /* seconds after the minute - [0,59] */int tm_min;     /* minutes after the hour - [0,59] */int tm_hour;    /* hours since midnight - [0,23] */int tm_mday;    /* day of the month - [1,31] */int tm_mon;     /* months since January - [0,11] */int tm_year;    /* years since 1900 */int tm_wday;    /* days since Sunday - [0,6] */int tm_yday;    /* days since January 1 - [0,365] */int tm_isdst;   /* daylight savings time flag */};
#define _TM_DEFINED
#endif/* Clock ticks macro - ANSI version */#define CLOCKS_PER_SEC  1000/* Extern declarations for the global variables used by the ctime family of* routines.*//* non-zero if daylight savings time is used */
_CRTIMP extern int _daylight;/* offset for Daylight Saving Time */
_CRTIMP extern long _dstbias;/* difference in seconds between GMT and local time */
_CRTIMP extern long _timezone;/* standard/daylight savings time zone names */
_CRTIMP extern char * _tzname[2];/* Function prototypes */_CRTIMP char * __cdecl asctime(const struct tm *);
_CRTIMP char * __cdecl ctime(const time_t *);
_CRTIMP clock_t __cdecl clock(void);
_CRTIMP double __cdecl difftime(time_t, time_t);
_CRTIMP struct tm * __cdecl gmtime(const time_t *);
_CRTIMP struct tm * __cdecl localtime(const time_t *);
_CRTIMP time_t __cdecl mktime(struct tm *);
_CRTIMP size_t __cdecl strftime(char *, size_t, const char *,const struct tm *);
_CRTIMP char * __cdecl _strdate(char *);
_CRTIMP char * __cdecl _strtime(char *);
_CRTIMP time_t __cdecl time(time_t *);#ifdef  _POSIX_
_CRTIMP void __cdecl tzset(void);
#else
_CRTIMP void __cdecl _tzset(void);
#endif/* --------- The following functions are OBSOLETE --------- */
/* The Win32 API GetLocalTime and SetLocalTime should be used instead. */
unsigned __cdecl _getsystime(struct tm *);
unsigned __cdecl _setsystime(struct tm *, unsigned);
/* --------- The preceding functions are OBSOLETE --------- */#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#define _SIZE_T_DEFINED
#endif#ifndef _MAC
#ifndef _WTIME_DEFINED/* wide function prototypes, also declared in wchar.h */_CRTIMP wchar_t * __cdecl _wasctime(const struct tm *);
_CRTIMP wchar_t * __cdecl _wctime(const time_t *);
_CRTIMP size_t __cdecl wcsftime(wchar_t *, size_t, const wchar_t *,const struct tm *);
_CRTIMP wchar_t * __cdecl _wstrdate(wchar_t *);
_CRTIMP wchar_t * __cdecl _wstrtime(wchar_t *);#define _WTIME_DEFINED
#endif
#endif  /* ndef _MAC */#if     !__STDC__ || defined(_POSIX_)/* Non-ANSI names for compatibility */#define CLK_TCK  CLOCKS_PER_SEC_CRTIMP extern int daylight;
_CRTIMP extern long timezone;
_CRTIMP extern char * tzname[2];_CRTIMP void __cdecl tzset(void);#endif  /* __STDC__ */#ifdef  __cplusplus
}
#endif#ifdef  _MSC_VER
#pragma pack(pop)
#endif  /* _MSC_VER */#endif  /* _INC_TIME */
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
int mian()
{char *wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};  // 指针数组time_t timep;                             //struct tm *p;time(&timep);printf("%s",ctime(&timep));p=gmtime(&timep);printf("%s",asctime(p));printf("%d-%d-%d",(1990+p->tm_year),(1+p->tm_mon),p->tm_mday);printf("%s %d:%d:%d\n",wday[p->tm_wday],p->tm_hour,p->tm_min,p->tm_sec);p=localtime(&timep);printf("%d-%d-%d",(1900+p->tm_year),(1+p->tm_mon),p->tm_mday);printf("%s %d:%d:%d\n",wday[p->tm_wday],p->tm_hour,p->tm_min,p->tm_sec);return 0;
}

低级错误,哎呦我的天呐!!!

八、诊断函数

assert()函数是诊断函数,它的作用是测试一个表达式的值是否为false(0),且在条件为false时终止程序,参数的表达式的结果是一个整型数据。assert()函数是在标准函数库<assert.h>头文件中定义

九、命令行参数

  • 标准c语言允许main()有或没有参数列表。
  • 因此主函数main()可以使用一个或多个参数
  • int mian(int argc,char *argv[])

 

十、其他函数

exit()函数表示程序结束,它的返回值将被忽略。它定义在<stdlib.h>文件中

  • qsort()函数包含在<stdlib.h>文件中,此函数根据给出的比较进行快速排序通过指针移动实现排序。排序之后结果任然放在原函数中,使用qsort函数必须自己写一个比较函数。
  • void qsort(void *base,int n,int size,int(*fcmp)(const void *,const void*));
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char stringlist[5][6] = {"boy","girl","man","woman","human"};
int intlist[5]= {3,2,5,1,4};
int sort_stringfun(const void *a,const void *b);
int sort_intfun(const void *a,const void *b); 
/*声明sort_intfun函数,返回值类型为int,不可修改的void *b const为修饰符意为不可修改 */int main(void)
{int x;printf("字符串排序:\n");qsort((void *)stringlist,5,sizeof(stringlist[0]),sort_stringfun);for(x=0;x<5;x++)printf("%s\n",stringlist[x]);printf("整数排序:\n");qsort((void *)intlist,5,sizeof(intlist[0]),sort_intfun);for(x=0;x<5;x++)printf("%d\n",intlist[x]);return 0;
}
int sort_stringfun(const void *a,const void *b)
{return(strcmp((const char *)a,(const char *)b));
}
int sort_intfun(const void *a,const void *b)
{return *(int *)a-*(int *)b;
}

十一、综合应用:猜字游戏

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define MAX 9int main(void) {int b=0;int n;int sum =0;char array[100];char *p=array;int num;srand((unsigned)time(NULL));// 随机数播种函数num=1+rand()%MAX;   // 设定随机数printf("随机数已经准备好,范围1到9\n");while(!b) { // 猜不对就一直循环sum+=1;printf("请输入你猜的数字\n");scanf("%s",p);if(strlen(p)==1) {  // 返回字符串p的长度不包括ullif(isalpha(*p)!=0) {  // isalpha(int c)c为字母时返回一个非零数,否则返回零printf("请输入数字,不是字母\n");} else if(ispunct(*p)!=0) { // int ispunct(int c) 如果整数c是可打印的(除空格,数字,字母之外)返回非零,否则返回零printf("请输入数字,不是标点符号");} else {n=atoi(p);if(n==num) {b=1;printf("你太厉害了!你共猜中了%d次\n",sum);} else if(n<num && n>=0) {printf("你猜小了,继续努力\n");} else if(n>num && n<=9) {printf("你猜大了!继续努力!\n");}}} else {printf("数字范围是1到9,你输入的数据不对\n");}}return 0;
}

 


http://chatgpt.dhexx.cn/article/xb3qgupw.shtml

相关文章

MySQL 远程访问失败的原因及解决方案

文章目录 1、失败的原因1.1、 /etc/mysql/my.cnf文件中bind-address 127.0.0.1没有注释掉1.2、 端口3306没有开放&#xff0c;使用 ss -tlnp 命令查看网络端口开启状态1.3、 在MySQL数据库user表中host字段值为localhost 2、解决方案2.1、/etc/mysql/my.cnf文件中&#xff0c;…

mysql5.7.6允许远程_mysql5.7 设置远程访问

mysql5.7设置远程访问不是和网上说的一样建个用户赋个权限就可以访问的。比如下边这个就是建用户赋权限&#xff0c;可能在之前的版本可以&#xff0c;但是我在我的mysql上一直不行。为此烦了好久&#xff01;&#xff01;&#xff01;项目都耽误了&#xff01;&#xff01; 一…

Mysql远程访问权限

在阅读本文时&#xff0c;推荐先走读完浅谈Mysql权限控制一文。 Mysql启动默认的端口3306是打开的&#xff0c;此时打开了mysqld的网络监听&#xff0c;允许用户远程通过账号密码连接本地数据库&#xff0c;Mysql数据库默认是允许远程用户连接服务器的。 那么&#xff0c;为什…

Mysql远程访问限制ip

一、Mysql允许指定IP远程访问 1、登录mysql -u root -p 之后输入密码进行登陆 2、查看用户表 首先要先指定使用mysql数据库&#xff0c;然后再进行查询操作//进入mysql数据库 mysql> use mysqlmyql> select Host,User from user;下面的列表就是查询user表后可以访问…

CentOS7 开启mysql远程访问

一.开启mysql的远程访问权限 可以先查看下表的内容 1.用mysql自带的客户端连接mysql mysql mysql -uroot -p 输入root用户的密码 进入mysql命令行模式 mysql >select user,host from mysql.user; 2.如果要直接使用root用户远程连接,直接执行以下sql 方法一: mysql>upda…

MySQL设置远程访问权限

当我们在日常开发中&#xff1b;需要连接其他同事的数据库或者其他服务器的数据库&#xff1b;可能会出现以下情况 我们输入的用户和密码都正确&#xff1b;但是提示我们用户没有权限&#xff1b;这个用户指的是远程连接的电脑ip没有访问权限&#xff1b;不是mysql的用户没有权…

Mysql允许远程访问

目录 远程访问条件配置1、配置绑定地址2、授权用户改表授权 远程访问条件 mysql允许远程访问有两个必要条件 外部能访问到mysql开启的端口用户有权限访问 配置 1、配置绑定地址 mysql配置绑定的地址是127.0.0.1&#xff0c;只允许本机连接。为使其他主机可以访问mysql服务…

授权MySQL可以远程访问

MySql-Server 出于安全方面考虑默认只允许本机(localhost, 127.0.0.1)来连接访问.要实现远程访问必须给root修改可以远程访问的权限。 授权步骤&#xff1a; 1.进入数据库连接mysql -u root -p&#xff1b; use mysql&#xff1b; 2.查询用户表命令&#xff1a;select User,au…

配置MySQL远程访问

如果通过数据库客户端Navicat等 远程连接 MySQL&#xff0c;出现了 2003 错误&#xff0c;说明服务器上的数据库没有配置远程连接。 因为MySQL默认是只允许本地连接的。 远程连接MYSQL必须完成下面的配置。 1. 授权远程用户登录 # 在服务器上进入MySQL控制台 $ mysql -u roo…

Ubuntu设置MySQL远程访问

文章目录 一、设置mysql远程访问 -> 第一种方式二、设置mysql远程访问 -> 第二种方式三、Windows上MySQL管理器下载与远程访问使用方法下载与安装使用 一、设置mysql远程访问 -> 第一种方式 编辑mysql配置文件&#xff0c;把其中bind-address 127.0.0.1注释了 sudo…

MySQL远程访问配置

MySQL远程访问配置 1. 进入MySQL安装目录下的bin目录&#xff08;如果配置过环境变量就直接到第二步&#xff09; 2. 在地址栏输入cmd打开命令行窗口&#xff08;如果配置过环境变量直接WinR输入cmd回车即可&#xff09; 3. 输入命令mysql -uroot -p回车&#xff0c;然后输入…

远程访问Mysql

1.远程虚拟机登上mysql客户端&#xff0c;show databases查看有哪些数据库&#xff0c;use mysql进入该数据库 show tables;查看表 select user,host from user;看host属性&#xff0c;root用户只能在本地访问数据库。 更改host, 执行 update user set host% where userroot…

MySQL远程连接的设置

与SQL Server类似&#xff0c;MySQL在需要远程操纵其他电脑时&#xff0c;也需要对其做远程连接的相应设置&#xff0c;具体操作如下。首先&#xff0c;我们需要解决不能远程访问的问题。在控制台命令中输入命令: mysql –uroot –p&#xff08;对应安装软件时设置的密码&#…

mysql远程访问

问题场景&#xff1a; windows局域网内访问mysql数据库 连接失败报10060 原因分析&#xff1a; 查阅了一些资料&#xff0c;问题出现在网络访问上。 mysql远程访问权限 mysql本身设定有访问权限&#xff0c;一般来讲安装的时候如果没有允许远程访问&#xff0c;非localhost…

Docker——四种网络模式解析

Docker四种网络模式解析 网络资源详解——Docker0网卡与四种网络模式Docker0网卡及四种网络模式host模式container模式none模式bridge模式网络模式的使用方法——指定模式和指定ip 网络资源详解——Docker0网卡与四种网络模式 安装完Docker时&#xff0c;会发现系统自动创建了…

Docker容器网络模式

目录 一、Docker网络实现原理 二、Docker的网络模式 1、Host模式 2、Container模式 3、none模式 4、bridger模式 bridge模式原理 5、overlay模式 6、自定义网络模式 为什么要自定义网络模式 创建自定义网络 删除docker网络 创建指定容器的ip 暴露端口 把宿主机文件传…

你应该学会的docker网络模式

学习Docker网络的七种模式 0. 双网卡1. the default Bridge2. User-defined 自定义桥接网络3. the Host3. MacVLAN3. the macVLAN&#xff08;802.1q&#xff09;4. the IPVlan (L2)5. the IPVlan (L3)6. Overlay7. None 0. 双网卡 Host: Linux vm 网卡&#xff1a;NATHost-on…

Docker系列(8) Docker网络(2)-- Docker四种网络模式简介

本篇介绍Docker单机网络的四种模式 Docker网络模式配置说明host模式–nethost容器和宿主机共享Network namespacecontainer模式–netcontainer:NAME_or_ID容器和宿主机共享Network namespacenone模式–netnone容器有独立的Network namespace&#xff0c;但并没有对其进行任何网…

docker 的网络模式

一、docker网络概述 1、docker网络实现的原理 Docker使用Linux桥接&#xff0c;在宿主机虚拟一个Docker容器网桥(docker0)&#xff0c;Docker启动一个容器时会根据Docker网桥的网段分配给容器一个IP地址&#xff0c;称为Container-IP&#xff0c; 同时Docker网桥是 每个容器的…

Docker系列九:Docker网络模式详解及容器间通信

目录 一&#xff1a;前言 二&#xff1a;Docker的网络模式 2.1&#xff1a;bridge 网络模式(桥接模式) 2.2&#xff1a;host 网络模式 2.3&#xff1a;none网络模式 2.4&#xff1a;Container 网络模式 三&#xff1a;Docker自定义网络(推荐) 为容器扩容其他网络 断开…