
函数功能
扳手的海角
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
13章13.4题---fprintf()以及fscanf()以及 (正确的)错误信息打印
#include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 41 int main(void) { FILE *fp; char word[MAX]; if ((fp = fopen("C:\\Users\\李国强\\source\\repos\\13\\13\\words.txt", "a+")) == NULL); { fprintf(stdout, "can't create原创 2020-12-14 22:31:12 · 205 阅读 · 4 评论 -
volatile类型限定符
val1 = x; //中间一些不使用x的代码 val2 = x; 有缺陷,中间假如是一些不使用x的代码,就没关系的 . . . 但是若是x为网口数据这种不断波动的数据类型的话,我们的寄存器保存住第一次的x的数据,而中间x会不断的变换,那么val2的值会是一个新的数据,但是此时寄存器中保存的原始x的值会在val2需要使用时读取出来赋值给它,此时便会冲突。 . . . 可以通过添加const的方式解决这个问题 const volatile int loc; ...原创 2020-12-05 22:00:39 · 164 阅读 · 0 评论 -
11章例题的代码理解--fgets( )、输入流、fputs( )函数、输出流
11.9 #include <stdio.h> int main(void) { char a[5]; int i; puts("Enter strings (empty line to quit):"); while (fgets(a, 5, stdin) != NULL && a[0] != '\n') { i = 0; //遍历字符串,直到遇到换行符或空字符。如果先遇到换行符,下面的if语句就将其替换成空字符:如果先遇到空字符,else部分便丢弃输入原创 2020-12-02 17:25:59 · 138 阅读 · 0 评论 -
使用strtol()-把字符串转换为数字,且按照进制转换
strtol()把字符串转换成long类型值 strtol()函数原型: long strtol (const char * restrict nptr, char ** restrict endptr,int base ); 这里,nptr是指向转换字符串的指针,endptr是一个指针的地址,该指针被设置为标识输入数字结束字符的地址。base表示以什么进制写入数字 /*strcnvt.c --使用strtol()*/ #include <stdio.h> #include <stdlib原创 2020-11-15 21:43:17 · 282 阅读 · 0 评论 -
strcpy--拷贝函数,拷贝整个字符串,但目标数组无法检测能否装下拷贝字符
#define SIZE 40 #define LIM 5 int main() { char qwords[LIM][SIZE]; char temp[SIZE]; int i = 0; //行统计 printf("Enter %d words beginning with q:\n", LIM); while(i < LIM && s_gets(temp, SIZE)) { /* if(temp[0] != 'q') //判断temp第一个字符是否是以q开头原创 2020-11-14 15:41:55 · 228 阅读 · 0 评论 -
strncmp--带n,可以比较指定大小的字符
比较数组的每行字符串的前5个字符和astro相等吗 #include <stdio.h> #include <string.h> char * s_gets(char * st, int n) { char * ret_val; int i = 0; ret_val = fgets(st, n, stdin); if (ret_val) //即,ret_val != NULL { while (st[i] != '\n' && st[i] != '\0原创 2020-11-14 15:22:58 · 266 阅读 · 0 评论 -
strcmp函数--多个比较条件理解
//每次不相同,统计一下行 /* ct < LIM:行数不可以大于给与的多维数组的行数 s_gets(input[ct],SIZE) != NULL :每行的一维数组,内容不为空 input[ct][0] != '\0' :每行数组的第一个元素不为 空字符 strcmp(input[ct], STOP) != 0 :==0代表比较字符一样, !=0才会进入下面统计走了多少行 #include <stdio.h> #include <string.h> #define SIZE原创 2020-11-14 15:16:34 · 571 阅读 · 0 评论 -
strcmp()函数,如果两个字符串参数相同,该函数就返回0,否则返回非零值
“字符串”就相当于指针,用双引号括起来的内容被视为指向该字符串储存位置的指针。害类似于把数组名作为指向该数组位置的指针。 #include<stdio.h> #include<string.h> #define N 30 #define M 13 #define ANSWER "Greas" char *s_gets(char *, int ); int main(void) { char a[N]; puts("Who is buried in Grant's tomb?"原创 2020-11-11 21:31:35 · 3372 阅读 · 0 评论 -
strncat--更加安全,拥有可添加多少字符的保险
strncat(bug, add, available);中的int available #include<stdio.h> #include<string.h> #define N 30 #define M 13 char *s_gets(char *st, int n); int main(void) { int available; char flower[N]; char add[] = "is a sss ddd fff gg"; char bug[M];原创 2020-11-10 22:33:48 · 366 阅读 · 0 评论 -
strcat()函数理解--无法检查第1个数组是否能容纳第2个字符串
第一个数组必须足够大去容纳第二个数组的数据 #include<stdio.h> #include<string.h> #define SIZE 80 /* strcat()(用于拼接字符串)函数接受两个字符串作为参数。 该函数把第2个字符串的备份附加在第1个字符串末尾,并把拼接后形成的新字符串作为第1个字符串,第2个字符串不变。 strcat()函数的类型是char *(即,指向char的指针)。 strcat()函数返回第1个参数,即拼接第2个字符串后的第1个字符串的地址。 */原创 2020-11-07 22:11:18 · 222 阅读 · 0 评论 -
strchr函数的理解-返回字符首次出现的地址信息-带编程例子
#define SECOND_DEMO #include <stdio.h> #include <conio.h> #include <string.h> #pragma warning (disable:4996) int main(void) { char string[17]; char *ptr; char c = 'a'; strcpy(string, "This is a string"); ptr = strchr(string, c); .原创 2020-10-28 09:25:02 · 490 阅读 · 0 评论 -
strlen(string)---统计字符串长度
在这里插入代码片 #include<stdio.h> #include<string.h> void fit(char *string, unsigned int size) { if (strlen(string) > size) //strlen(string)统计字符串长度 { string[size] = '\0'; } } int main(void) { char mes[] = "aa gg sss ddddaaaaaaa," "but原创 2020-11-07 21:22:26 · 1196 阅读 · 0 评论