06 2021 档案
摘要:1、自定义函数 test1 <- function(x = 5,y) ## 自定义函数test { a = x / y print(a) } test1(10,100) ## 使用位置参数,按顺序x = 10, y = 100 test1(y = 10, x = 100) ## 关键字参数 直接定义
阅读全文
摘要:1、 rm(list = ls()) dir() for (i in list.files(pattern=".r$")) { source(i) } 2、 rm(list = ls()) dir() for (i in dir()) { if(substr(i,nchar(i)-1,nchar(i
阅读全文
摘要:R语言中如何在函数内部定义全局变量。 1、在函数内部定义的变量无法在函数外调用 test1 <- function(x, y) { a <- x + y print(a) } test1(10,20) print(a) 2、在函数内定义全局变量 test2 <- function(x, y) { a
阅读全文
摘要:1、问题 [root@centos79 software]# dnf install R bash: dnf: command not found... 2、安装dnf [root@centos79 software]# yum install epel-release Loaded plugins
阅读全文
摘要:1、默认情况下root不能登录ssh 2、修改ssh服务配置文件 root@ubuntu01:~/Desktop# whoami root root@ubuntu01:~/Desktop# vim /etc/ssh/sshd_config ………… # Authentication: #LoginG
阅读全文
摘要:1、查看当前主机名 root@liujiaxin01-virtual-machine:~/Desktop# hostname liujiaxin01-virtual-machine ##太长 2、修改主机名 root@liujiaxin01-virtual-machine:~/Desktop# wh
阅读全文
摘要:Ubuntu 20.04.2默认不能进行root登录 1、查看系统版本 liujiaxin01@liujiaxin01-virtual-machine:~/Desktop$ whoami liujiaxin01 liujiaxin01@liujiaxin01-virtual-machine:~/De
阅读全文
摘要:1、问题 (1)、传输工具 2、安装ssh服务 liujiaxin01@liujiaxin01-virtual-machine:~$ whoami liujiaxin01 liujiaxin01@liujiaxin01-virtual-machine:~$ sudo apt-get install
阅读全文
摘要:1、系统信息 liujiaxin01@liujiaxin01-virtual-machine:~/Desktop$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.0
阅读全文
摘要:1、问题 [root@localhost ~]# systemctl restart network Failed to restart network.service: Unit network.service not found. 2、查看iP [root@localhost ~]# ifcon
阅读全文
摘要:1、测试数据 [root@centos7 test]# cat a.txt 4 8 2 6 2、直接求和 [root@centos7 test]# awk '{sum += $1}END{print sum}' a.txt 20 3、累积求和 [root@centos7 test]# cat a.t
阅读全文
摘要:1、创建测试文件: [root@centos7 test]# touch {a..f}.txt [root@centos7 test]# ls a.txt b.txt c.txt d.txt e.txt f.txt 2、删除b.txt文件以外的所有文件 method1: [root@centos7
阅读全文
摘要:以centos7.9为例。 1、 [root@centos7 test]# uname -a Linux centos7 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
阅读全文
摘要:1、创建5个测试数据文件 [root@centos7 test]# dd if=/dev/zero bs=1M count=100 of=a.txt [root@centos7 test]# dd if=/dev/zero bs=1M count=10 of=b.txt [root@centos7
阅读全文
摘要:c语言中double关键字和double关键字的区别。 1、 #include <stdio.h> int main(void) { float num1; double num2; //以上声明了两种不同类型的变量 printf("Please enter two floating point n
阅读全文
摘要:安装软件后,如果不针对软件的可执行程序设置环境变量,则在每次使用软件时,均需要调用软件可执行程序的绝对路径,相对繁琐。 以下以plink软件为例,将plink的可执行程序加入环境变量。 1、首先下载plink软件,http://zzz.bwh.harvard.edu/plink/download.s
阅读全文
摘要:1、测试数据下载 链接:https://pan.baidu.com/s/1EfffExvtxZYI1QLuxUZQ_g 提取码:5wfe 数据为plink 格式数据test.map、test.ped ; 一共包含三个品种,DOR、GMM、SUN各20个样本。 2、下载、安装detectRUNS包 i
阅读全文
摘要:1、测试数据下载 链接:https://pan.baidu.com/s/1EfffExvtxZYI1QLuxUZQ_g 提取码:5wfe 数据为plink 格式数据test.map、test.ped ; 一共包含三个品种,DOR、GMM、SUN各20个样本。 2、提取两个品种数据 grep -E "
阅读全文
摘要:1、测试数据下载 链接:https://pan.baidu.com/s/1EfffExvtxZYI1QLuxUZQ_g 提取码:5wfe 数据为plink 格式数据test.map、test.ped ; 一共包含三个品种,DOR、GMM、SUN各20个样本。 2、下载gcta软件,官网: https
阅读全文
摘要:1、测试数据下载 链接:https://pan.baidu.com/s/1EfffExvtxZYI1QLuxUZQ_g 提取码:5wfe 数据为plink 格式数据test.map、test.ped ; 一共包含三个品种,DOR、GMM、SUN各20个样本。 2、使用plink将测试数据转化为二进制
阅读全文
摘要:1、测试数据下载 链接:https://pan.baidu.com/s/1EfffExvtxZYI1QLuxUZQ_g 提取码:5wfe 数据为plink 格式数据test.map、test.ped ; 一共包含三个品种,DOR、GMM、SUN各20个样本。 2、运行plink软件,命令如下: pl
阅读全文
摘要:c语言中基本数据类型 1、 C语言提供了两大系列多种类型的数据。 两大数据类型分别是: 整数类数据类型和浮点型数据类型。 signed、unsigned short、int、long;char; float、double、long double;_Bool;_Complex; _Imaginary;
阅读全文
摘要:c语言中利用itoa函数将整数值以二进制、八进制、十六进制显示。 1、 #include <stdlib.h> #include <stdio.h> int main(void) { int num = 100; char bin[1000]; char oct[1000]; char hex[10
阅读全文
摘要:c语言中以10进制、8进制、16进制显示同一个数字。 1、 #include <stdio.h> int main(void) { int x = 100; printf("dec: %d; octal: %o; hexadecimal: %x\n", x, x, x); printf("dec:
阅读全文
摘要:1、文本复制 fgetc、fputc函数实现 #include <stdio.h> int main(void) { int ch; FILE *sfp; FILE *dfp; char sfilename[FILENAME_MAX]; char dfilename[FILENAME_MAX]; p
阅读全文
摘要:1、 #include <stdio.h> int main(void) { int ch; FILE *sfp; FILE *dfp; char sfile[FILENAME_MAX]; char dfile[FILENAME_MAX]; printf("source file name: ");
阅读全文
摘要:1、 #include <stdio.h> #include <ctype.h> int main(void) { int n; unsigned long count = 0; unsigned char buf[16]; FILE *fp; char fname[FILENAME_MAX]; p
阅读全文
摘要:1、13-11 #include <stdio.h> int main(void) { FILE *fp; int i; double b[10]; double a[] = {0.1,1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1}; if((fp = fopen("tmp
阅读全文
摘要:c语言向文本文件、二进制文件中写入实数。 1、 #include <stdio.h> int main(void) { FILE *fp; double pi = 3.14159265358979323846; printf("pi from value: %23.21f.\n", pi); //
阅读全文
摘要:13-8、 #include <stdio.h> int main(void) { FILE *sfp; FILE *dfp; int ch; char sfilename[FILENAME_MAX]; char dfilename[FILENAME_MAX]; printf("Please inp
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *sfp; FILE *dfp; int ch; char sfilename[FILENAME_MAX]; char dfilename[FILENAME_MAX]; printf("Please input
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("Please input the filename: "); scanf("%s", filename); if
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("Please input the filename: "); scanf("%s", filename); if
阅读全文
摘要:1、显示a.txt文件的内容 #include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("Please input the filename: "); scanf("%s", f
阅读全文
摘要:1、 #include <stdio.h> #include <time.h> void put_data(void) { FILE *fp; if((fp = fopen("time.txt", "r")) == NULL) { printf("\aThe program is ran for t
阅读全文
摘要:1、 #include <stdio.h> #include <time.h> void put_data(void) { FILE *fp; if((fp = fopen("time.txt", "r")) == NULL) printf("\aThe program is running for
阅读全文
摘要:利用函数库获取当前时间。 1、 #include <stdio.h> #include <time.h> int main(void) { time_t current = time(NULL); struct tm *timer = localtime(¤t); printf("cur
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; char name[128]; double height, weight; if((fp = fopen("a.txt", "w")) == NULL) printf("\aFile open fai
阅读全文
摘要:1、写入日期和时间 #include <stdio.h> #include <time.h> int main(void) { FILE *fp; time_t current = time(NULL); struct tm *timer = localtime(¤t); if((fp
阅读全文
摘要:1、 #include <stdio.h> typedef struct{ char name[128]; double height; double weight; }Type1; void swap(Type1 *x, Type1 *y) { Type1 tmp = *x; *x = *y; *
阅读全文
摘要:c语言中统计文件字符数 1、 #include <stdio.h> int main(void) { FILE *fp; char c1[128]; int lines = 0; fp = fopen("a.txt", "r"); while(fscanf(fp, "%s", c1) == 1) {
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; int lines = 0; char name[128]; double height, weight; double hsum = 0, wsum = 0; if((fp = fopen("a.tx
阅读全文
摘要:13 - 1、 #include <stdio.h> int main(void) { FILE *fp; char filename[FILENAME_MAX]; printf("filename: "); scanf("%s", filename); if((fp = fopen(filenam
阅读全文
摘要:1、 #include <stdio.h> int main(void) { int ch; FILE *sfp; FILE *dfp; char sfile[FILENAME_MAX]; char dfile[FILENAME_MAX]; printf("source file name: ");
阅读全文
摘要:1、 #include <stdio.h> #include <ctype.h> int main(void) { int n; unsigned long count = 0; // count初始值为0, 为什么是unsigned long? unsigned char buf[16]; //字
阅读全文
摘要:1、 #include <stdio.h> #include <time.h> char data_file[] = "datatime.dat"; void get_data(void) { FILE *fp; if((fp = fopen(data_file, "r")) == NULL) pr
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; double a[10] = {1.1,2.1,3.1,4.1,5.1,6.1,7.1,8.1,9.1,0.1}; int i; for(i = 0; i < 10; i++) { printf("a[
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; // 定义指向FILE型的指针变量 double pi = 3.14159265358979323846; printf("Pi from value: %23.21f.\n", pi); // 直接输
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; // 声明指向FILE型的指针变量 double pi = 3.14159265358979323846; //声明 double型变量 printf("pi from value: %23.21f.\
阅读全文
摘要:1、 #include <stdio.h> #include <ctype.h> int main(void) { int ch; FILE *sfp; FILE *dfp; char sfile[FILENAME_MAX]; char dfile[FILENAME_MAX]; printf("sf
阅读全文
摘要:1、 #include <stdio.h> #include <ctype.h> int main(void) { int ch; FILE *sfp; FILE *dfp; char sfile[FILENAME_MAX]; char dfile[FILENAME_MAX]; printf("sf
阅读全文
摘要:1、 #include <stdio.h> int main(void) { int ch; FILE *sfp; FILE *dfp; char sfile[FILENAME_MAX]; char dfile[FILENAME_MAX]; printf("sfile name: "); scanf
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("filename: "); scanf("%s", filename); if((fp = fopen(file
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; int ch; char filename[FILENAME_MAX]; printf("please input filename: "); scanf("%s", filename); if((fp
阅读全文
摘要:c语言中显示文件内容。 1、 #include <stdio.h> int main(void) { FILE *fp; // 定义FILE型的指针变量,用于接收fopen函数返回的流指针 int ch; // 声明字符,注意是int char filename[FILENAME_MAX]; //
阅读全文
摘要:1、 #include <stdio.h> #include <time.h> char filename[] = "timedata.dat"; void put_dat(void) { FILE *fp; if((fp = fopen(filename, "r")) == NULL) print
阅读全文
摘要:1、 #include <stdio.h> #include <time.h> char file[] = "datatime.dat"; void put_data(void) { FILE *fp; if((fp = fopen(file,"r")) == NULL) // 未检测到datati
阅读全文
摘要:c语言中写入日期和时间。 1、 #include <stdio.h> #include <time.h> int main(void) { FILE *fp; time_t current = time(NULL); struct tm *timer = localtime(¤t); i
阅读全文
摘要:1、 #include <stdio.h> #include <time.h> // time_t数据类型,日历时间头文件 int main(void) { time_t current = time(NULL); // 利用time函数获取日历时间(返回1970之后的秒数,整型) struct t
阅读全文
摘要:1、 #include <stdio.h> #define NUMBER 6 typedef struct{ char name[128]; double height; double weight; }Type1; int main(void) { FILE *fp; fp = fopen("xx
阅读全文
摘要:1、 #include <stdio.h> #include <string.h> typedef struct{ char name[128]; double height; double weight; }Type1; void swap2(Type1 *x, Type1 *y) { Type1
阅读全文
摘要:1、 #include <stdio.h> typedef struct{ char name[128]; double height; double weight; }Type1; void swap(Type1 *x, Type1 *y) { Type1 tmp = *x; *x = *y; *
阅读全文
摘要:1、 #include <stdio.h> typedef struct{ char name[128]; double height; double weight; }Typex; void swap(Typex *x, Typex *y) { Typex tmp = *x; *x = *y; *
阅读全文
摘要:1、 #include <stdio.h> #define NUMBER 5 void sort(int x[], int n) { int i, j; // i表示具体循环的轮数, j表示每一轮参与比较的元素的下标 for(i = 0; i < n - 1; i++)//一共循环的轮数n - 1,
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; int lines = 0; double c1, c2, c3; double c1sum = 0, c2sum = 0, c3sum = 0; if((fp = fopen("a.txt","r")
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; //打开文件前必须要定义FILE*型指针变量 int lines = 0; char name[128]; double height, weight; double hsum = 0, wsum =
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; // 打开文件前,必须定义FILE*型指针变量 char file[128]; printf("please input the file: "); scanf("%s", file); fp = fo
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; // 打开文件前,必须定义FILE*型指针变量。 char file[128]; printf("please input the filename: "); scanf("%s", file); //
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; //打开文件时,必须要提前在函数中定义FILE*型指针变量, 然后将fopen函数返回的FILE型指针对象赋值给定义的指针变量,就可以通过该变量来修改文件了 fp = fopen("a.txt","r"
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; char filename[128]; printf("filename: "); scanf("%s", filename); fp = fopen(filename, "r"); if(fp !=
阅读全文
摘要:1、 #include <stdio.h> int main(void) { FILE *fp; char filename[128]; printf("filename: "); scanf("%s", filename); fp = fopen(filename, "r"); if(fp !=
阅读全文
摘要:1、 #include <stdio.h> #include <math.h> #define sqr(x) ((x) * (x)) typedef struct{ double x; double y; }Point; typedef struct{ Point pt; double fuel;
阅读全文
摘要:c语言中用结构体表示点的坐标,并计算两点之间的距离 1、 #include <stdio.h> #include <math.h> #define sqr(x) ((x) * (x)) typedef struct{ double x; double y; }Point; double dist(P
阅读全文
摘要:1、 1.1 #include <stdio.h> #include <string.h> #define NUMBER 5 #define NAME_LEN 64 typedef struct{ char name[NAME_LEN]; int height; float weight; long
阅读全文
摘要:c语言中的结构体数组(数组元素为结构体)。 1、 #include <stdio.h> #include <string.h> #define NUMBER 5 #define NAME_LEN 64 typedef struct{ char name[NAME_LEN]; int height;
阅读全文
摘要:1、 #include <stdio.h> typedef struct{ int x; long y; double z; }Assign; Assign fun(int a, long b, double c) { Assign tmp; tmp.x = a; tmp.y = b; tmp.z
阅读全文
摘要:1、 #include <stdio.h> #define NAME_LEN 64 typedef struct student{ char name[NAME_LEN]; int height; float weight; long schols; }Student; void judg(Stud
阅读全文
摘要:1、 #include <stdio.h> struct xyz{ int x; long y; double z; }; struct xyz fun(int a, long b, double c) //函数的返回类型为struct xyz型 { struct xyz tmp; //声明结构体对
阅读全文
摘要:typedef的作用是对数据类型进行同义声明。 1、 #include <stdio.h> #define NAME_LEN 64 typedef struct student{ //结构的类型名是struct student, 此处使用typedef为类型名strucnt student声明了St
阅读全文
摘要:c语言中将结构体对象指针作为函数的参数实现对结构体成员的修改。 1、 #include <stdio.h> #define NAME_LEN 64 struct student{ char name[NAME_LEN]; int height; float weight; long schols;
阅读全文
摘要:1、 #include <stdio.h> // main函数头文件 #define NAME_LEN 64 // 对象式宏 struct student{ // 结构体声明, student是结构名, struct student是类型名, name、height、weight和schols是结构
阅读全文
摘要:c语言中结构体成员的初始化, 结构体的成员可以单独赋值,也可以进行整体的初始化来实现一次性赋值。 1、 #include <stdio.h> //main函数头文件 #define NAME_LEN 64 // 对象式宏 struct student{ //结构体声明, student为结构名, s
阅读全文
摘要:c语言中结构体对象的声明、结构体成员的赋值、结构体成员的显示、.句点运算符的应用 1、 #include <stdio.h> //main 函数头文件 #include <string.h> // 字符串处理库函数头文件 #define NAME_LEN 64 struct student{ //
阅读全文
摘要:1、 #include <stdio.h> #include <string.h> #define NUMBER 5 #define NAME_LEN 64 void swap_int(int *x, int *y) { int tmp = *x; *x = *y; *y = tmp; } void
阅读全文
摘要:1、 #include <stdio.h> #include <math.h> #define sqr(x) ((x) * (x)) typedef struct{ double x; double y; } Point; typedef struct{ Point pt; double fuel;
阅读全文
摘要:c语言中具有结构体成员的结构体。 1、 #include <stdio.h> #include <math.h> #define sqr(x) ((x) * (x)) typedef struct{ double x; double y; } Point; typedef struct{ Point
阅读全文
摘要:c语言中利用结构体计算两点之间的距离。 1、 #include <stdio.h> #include <math.h> // c语言中基本数学运算的头文件,这里 sqrt函数使用到 #define sqr(x) ((x) * (x)) // 函数式宏,计算平方 typedef struct{ //结
阅读全文
摘要:1、 #include <stdio.h> #include <string.h> #define NUMBER 5 #define NAME_LEN 64 typedef struct{ char name[NAME_LEN]; int height; float weight; long sch
阅读全文
摘要:c语言中结构体数组。 1、 #include <stdio.h> #include <string.h> #define NUMBER 5 #define NAME_LEN 64 typedef struct{ char name[NAME_LEN]; int height; float weigh
阅读全文
摘要:1、 #include <stdio.h> struct xyz{ int x; long y; double z; }; struct xyz input(int a, long b, double c) { struct xyz tmp; tmp.x = a; tmp.y = b; tmp.z
阅读全文
摘要:1、 #include <stdio.h> #define NAME_LEN 64 typedef struct student{ // 为类型声明 typedef名, Student相当于 struct student char name[NAME_LEN]; int height; float
阅读全文
摘要:c语言中返回结构体的函数。(相同类型的结构体可以相互赋值。)。 1、 #include <stdio.h> struct xyz{ int x; long y; double z; }; struct xyz fun(int a, long b, double c) { struct xyz tmp
阅读全文
摘要:1、 #include <stdio.h> #define NAME_LEN 64 struct student{ //结构体声明 char name[NAME_LEN]; int height; float weight; long schols; }; int main(void) { stru
阅读全文
摘要:1、字符串转换为int型 #include <stdio.h> int toint(char *s1) { int i, j = 0; while(*s1) { for(i = 0; i <= 9; i++) { if((*s1 - '0') == i) j = j * 10 + i; } s1++
阅读全文
摘要:1、 #include <stdio.h> void del(char *s1) { char *tmp = s1; while(*tmp) { if(*tmp < '0' || *tmp > '9') *s1++ = *tmp++; else tmp++; } *s1 = '\0'; } int
阅读全文
摘要:1、原始函数,使用下标运算符 #include <stdio.h> #include <ctype.h> void upper(char x[]) { int tmp = 0; while(x[tmp]) { x[tmp] = toupper(x[tmp]); tmp++; } } void low
阅读全文
摘要:c语言标准函数库提供了字符串转换函数。 1、atoi 将字符串转换为int型 #include <stdio.h> #include <stdlib.h> int main(void) { char str1[128] = "123"; printf("coversion result: %d\n"
阅读全文
摘要:1、函数原型 #include <stdio.h> int strncmp(const char *s1, const char *s2, size_t n) { while(n && *s1 && *s2) { if(*s1 != *s2) return (unsigned char)*s1 -
阅读全文
摘要:1、函数原型 #include <stdio.h> int strcmp(const char *s1, const char *s2) { while(*s1 == *s2) { if(*s2 == '\0') return 0; s1++; s2++; } return (unsigned ch
阅读全文
摘要:1、函数原型 #include <stdio.h> char *strncat(char *s1, const char *s2, size_t n) { char *tmp = s1; while(*s1) s1++; while(n--) { if(!(*s1++ = *s2++)) break
阅读全文
摘要:1、函数原型 #include <stdio.h> char *strcat(char *s1, const char *s2) { char *tmp = s1; while(*s1) s1++; while(*s1++ = *s2++) ; return tmp; } int main(void
阅读全文
摘要:1、函数原型 #include <stdio.h> char *strncpy(char *s1, const char *s2, size_t n) { char *tmp = s1; while(n) { if(!(*s1++ = *s2++)) //此处是if语句,不能用while、for等,
阅读全文
摘要:1、函数原型。 #include <stdio.h> char *strcpy(char *s1, const char *s2) { char *t = s1; while(*s1++ = *s2++) ; return t; } int main(void) { char str1[128] =
阅读全文
摘要:1、 #include <stdio.h> char *mach(char *s, int key) { while(*s) { if(*s == key) return s; s++; } return NULL; } int main(void) { char str[128]; printf(
阅读全文
摘要:1、 #include <stdio.h> int count(const char *s, int key) { int j = 0; while(*s) { if(*s == key) j++; s++; } return j; } int main(void) { char str[128];
阅读全文
摘要:1、 #include <stdio.h> void put(const char *s) { while(*s) putchar(*s++); putchar('\n'); } int main(void) { char str[128]; printf("str: "); scanf("%s",
阅读全文
摘要:1、利用数组下标运算符 #include <stdio.h> int len(char s[]) { int len = 0; while(s[len]) len++; return len; } int main(void) { char str[128]; printf("str: "); sc
阅读全文
摘要:1、 #include <stdio.h> char *copy(char *d, const char *s) { char *t = d; while(*d++ = *s++) ; return t; } int main(void) { char str1[] = "abcd"; char s
阅读全文
摘要:1、c语言中字符串的复制 #include <stdio.h> char *copy(char *d, const char *s) { char *t = d; // 定义指向传入的字符串首字符的指针 while(*d++ = *s++) //当指针s所指元素不为null时,将s所指元素赋值给d所
阅读全文
摘要:1、 #include <stdio.h> int main(void) { char s[][5] = {"LISP","C","Ada"}; char *p[] = {"PAUL","X","MAC"}; int i; for(i = 0; i < 3; i++) { printf("s[%d]
阅读全文
摘要:1、原始程序,数组实现的字符串和指针实现字符串的不同点 #include <stdio.h> int main(void) { char *p = "123"; printf("first p = %s\n", p); p = "456"; printf("second p = %s\n", p);
阅读全文
摘要:1、strtoi #include <stdio.h> int strtoi(const char *s) { int i, j = 0; while(*s) { for(i = 0; i <= 9; i++) { if(*s - '0' == i) j = j * 10 + i; } s++; }
阅读全文
摘要:1、 #include <stdio.h> void del_num(char *s) //函数的形参为指针,也就是字符串数组的数组名,相当于指向数组第一个元素的指针。 { char *tmp = s; // 将指针tmp赋值为指针s,即指向传入的字符串数组的第一个元素的指针 while(*tmp)
阅读全文
摘要:1、 #include <stdio.h> void del(char *str) { while(*str) { if(*str >= '0' && *str <= '9') printf(""); else putchar(*str); str++; } } int main(void) { c
阅读全文
摘要:1、 #include <stdio.h> #include <ctype.h> void str_toupper(char *s) { while(*s) { *s = toupper(*s); s++; } } void str_tolower(char *s) { while(*s) { *s
阅读全文
摘要:1、c语言中转换字符串函数 atoi将字符型转换为int型。 c语言标准函数库提供了字符串转换函数。 <stdlib.h>。 #include <stdio.h> #include <stdlib.h> //c语言标准函数库 int main(void) { char str[128]; print
阅读全文
摘要:1、函数原型。 #include <stdio.h> int strncmp(const char *s1, const char *s2, size_t n) //函数返回int型,形参为两个指向char型的指针)和 unsigned 型n。 { while(n && *s1 && *s2) //
阅读全文
摘要:1、函数原型。 #include <stdio.h> int strcmp(const char *s1, const char *s2) // 函数返回int型,形参为两个指向char型的指针 { while(*s1 == *s2) //当元素相等时 { if(*s1 == '\0') // 判断
阅读全文
摘要:1、函数原型 #include <stdio.h> char *strncat(char *s1, const char *s2, size_t n) //函数的返回值为指向char型的指针,形参为两个指针(函数间数组(字符串数组)的传递是以指向数组第一个元素的指针进行的)和正整数n。 { char
阅读全文
摘要:1、函数原型 #include <stdio.h> char *strcat(char *s1, const char *s2) //函数返回类型为指针,形参为两个指针(为字符串数组的数组名,相当于指向数组第一个元素的指针) { char *tmp = s1; //将指针tmp赋值为s1指针,也就是
阅读全文
摘要:1、函数原型。 #include <stdio.h> char *strncpy(char *s1, const char *s2, size_t n) //函数的返回值为指针,形参为两个指针(字符串数组,相当于指向第一个字符的指针)和n(赋值字符个数)。 { char *tmp = s1; //将
阅读全文
摘要:1、函数原型(字符串的复制) #include <stdio.h> char *strcpy(char *s1, const char *s2) //函数的返回值为指向char型的指针, 形参为指向char型的指针 { char *tmp = s1; // 将指针tmp声明为s1,s1为传入的字符串
阅读全文
摘要:1、函数原型(利用指针求字符串的长度) #include <stdio.h> size_t strlen(const char *s) //函数头的形参为常数的、指向char型的指针,也就是接收的形参为指针(实际上传入的是字符串数组,函数间数组的传递实际上是通过指向第一个元素的指针完成的) { //
阅读全文