随笔分类 -  c/c++

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 30 下一页
摘要:c语言中利用结构体计算两点之间的距离。 1、 #include <stdio.h> #include <math.h> // c语言中基本数学运算的头文件,这里 sqrt函数使用到 #define sqr(x) ((x) * (x)) // 函数式宏,计算平方 typedef struct{ //结 阅读全文
posted @ 2021-06-04 16:39 小鲨鱼2018 阅读(1729) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-04 13:01 小鲨鱼2018 阅读(45) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-04 12:14 小鲨鱼2018 阅读(177) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-04 11:07 小鲨鱼2018 阅读(64) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> #define NAME_LEN 64 typedef struct student{ // 为类型声明 typedef名, Student相当于 struct student char name[NAME_LEN]; int height; float 阅读全文
posted @ 2021-06-04 10:27 小鲨鱼2018 阅读(63) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-04 09:49 小鲨鱼2018 阅读(2928) 评论(0) 推荐(0)
摘要:1、 #include <stdio.h> #define NAME_LEN 64 struct student{ //结构体声明 char name[NAME_LEN]; int height; float weight; long schols; }; int main(void) { stru 阅读全文
posted @ 2021-06-03 21:29 小鲨鱼2018 阅读(48) 评论(0) 推荐(0)
摘要: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++ 阅读全文
posted @ 2021-06-03 12:24 小鲨鱼2018 阅读(75) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-03 11:57 小鲨鱼2018 阅读(38) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-03 11:52 小鲨鱼2018 阅读(54) 评论(0) 推荐(0)
摘要:c语言标准函数库提供了字符串转换函数。 1、atoi 将字符串转换为int型 #include <stdio.h> #include <stdlib.h> int main(void) { char str1[128] = "123"; printf("coversion result: %d\n" 阅读全文
posted @ 2021-06-03 11:39 小鲨鱼2018 阅读(714) 评论(0) 推荐(0)
摘要: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 - 阅读全文
posted @ 2021-06-03 11:17 小鲨鱼2018 阅读(558) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-03 10:45 小鲨鱼2018 阅读(1662) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-03 10:04 小鲨鱼2018 阅读(225) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2021-06-03 09:49 小鲨鱼2018 阅读(1349) 评论(0) 推荐(0)
摘要: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等, 阅读全文
posted @ 2021-06-02 23:19 小鲨鱼2018 阅读(285) 评论(0) 推荐(0)
摘要: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] = 阅读全文
posted @ 2021-06-02 22:28 小鲨鱼2018 阅读(1770) 评论(0) 推荐(0)
摘要: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( 阅读全文
posted @ 2021-06-02 21:45 小鲨鱼2018 阅读(51) 评论(0) 推荐(0)
摘要: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]; 阅读全文
posted @ 2021-06-02 21:35 小鲨鱼2018 阅读(53) 评论(0) 推荐(0)
摘要: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", 阅读全文
posted @ 2021-06-02 21:30 小鲨鱼2018 阅读(49) 评论(0) 推荐(0)

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 30 下一页