找到 34423 篇文章 关于编程

C/C++ 中的 strdup() 和 strndup()

karthikeya Boyini
更新于 2020-06-24 11:27:03

6K+ 次浏览

strdup() 函数用于复制字符串。它返回一个指向空终止字节字符串的指针。以下是 C 语言中 strdup() 的语法:char *strdup(const char *string); 以下是一个 C 语言中 strdup() 的示例,示例 在线演示 #include <stdio.h> #include <string.h> int main() { char *str = "Helloworld"; char *result; result = strdup(str); printf("The string : %s", result); return 0; } 输出 The string : Helloworld strndup() 函数的工作方式类似于 strndup() 函数。此函数最多复制 size 个字节的字符串,即函数中给定的 size。它还返回一个指向空终止… 阅读更多

C语言中 fflush(stdin) 的用法

Samual Sam
更新于 2020-06-24 11:27:30

7K+ 次浏览

fflush(stdin) 函数用于刷新流的输出缓冲区。如果成功,它返回零;否则,返回 EOF 并设置 feof 错误指示器。以下是 C 语言中 fflush(stdin) 的语法:int fflush(FILE *stream); 以下是一个 C 语言中 fflush(stdin) 的示例,示例 在线演示 #include <stdio.h> #include <stdlib.h> int main() { char s[20] = "Helloworld"; printf("The string : %s", s); fflush(stdin); return 0; } 输出 The string : Helloworld

C语言中的 ispunct()

karthikeya Boyini
更新于 2020-06-24 11:28:00

96 次浏览

ispunct() 函数用于检查传递的字符是否为标点符号。如果它不是标点符号,则返回零;否则,返回非零值。以下是 C 语言中 ispunct() 的语法:int ispunct(int character); 以下是一个 C 语言中 ispunct() 的示例,示例 在线演示 #include <stdio.h> #include <ctype.h> int main() { int a = '!'; int b = 'a'; if(ispunct(a)) printf("The character is a punctuation."); else printf("The character is not a punctuation."); if(ispunct(b)) printf("The character is a punctuation."); else printf("The character is not a … 阅读更多

C语言中的 strspn()

Samual Sam
更新于 2020-06-24 11:28:22

153 次浏览

strspn() 函数用于计算第一个字符串的子字符串的长度,该子字符串存在于第二个字符串中。它返回该子字符串的长度。以下是 C 语言中 strspn() 的语法:size_t strspn(const char *string1, const char *string2); 以下是一个 C 语言中 strspn() 的示例,示例 在线演示 #include <stdio.h> #include <string.h> int main() { const char s1[] = "Helloworld!"; const char s2[] = "Hello"; int length = strspn(s1, s2); printf("The length of string : %d", length); return 0; } 输出 The length of string : 5

C/C++ 中的 strcoll()

karthikeya Boyini
更新于 2020-06-24 11:14:50

201 次浏览

strcoll() 函数用于使用特定于区域设置的排序顺序比较两个字符串。它返回:- 零,当两个字符串相同时;大于零的值,当第一个字符串大于另一个时;小于零的值,当第一个字符串小于另一个时。以下是 C 语言中 strcoll() 的语法:int strcoll(const char *first_string, const char *second_string); 以下是一个 C 语言中 strcoll() 的示例,示例 在线演示 #include <stdio.h> #include <string.h> int main () { const char s1[] = "Helloworld"; const char s2[] = "Blank"; char *result; result = strcoll(s1, s2); if(result > 0) … 阅读更多

C语言中的 strpbrk()

Samual Sam
更新于 2020-06-24 11:16:33

1K+ 次浏览

strpbrk() 函数用于查找第一个字符串的第一个字符,并将其与第二个字符串的任何字符匹配。如果未找到匹配项,则返回 NULL;否则,返回指向与第二个字符串的字符匹配的第一个字符串的字符的指针。以下是 C 语言中 strpbrk() 的语法:char *strpbrk(const char *string1, const char *string2) 以下是一个 C 语言中 strpbrk() 的示例,示例 在线演示 #include <stdio.h> #include <string.h> int main () { const char s1[] = "Helloworld"; const char s2[] = "Blank"; char *result; result = strpbrk(s1, … 阅读更多

C语言中的 scanf() 和 fscanf()

karthikeya Boyini
更新于 2020-06-24 11:17:07

2K+ 次浏览

scanf() 函数 scanf() 函数用于在 C 语言中从 stdin 读取格式化输入。它返回写入其中的字符总数,否则返回负值。以下是 C 语言中 scanf() 的语法:int scanf(const char *characters_set) 以下是一个 C 语言中 scanf() 的示例,示例 在线演示 #include <stdio.h> int main () { char s[20]; printf("Enter a string : "); scanf("%s", s); printf("Entered string : %s", s); return(0); } 输出 Enter a string : Peter! Entered string : Peter! fscanf() 函数 fscanf() 函数用于从给定流读取格式化输入… 阅读更多

C语言中 %d 和 %i 格式说明符的区别

Samual Sam
更新于 2020-06-24 11:17:57

2K+ 次浏览

格式说明符 %d 格式说明符 %d 将整数作为带符号的十进制整数来处理,这意味着无论它是负数还是正数,值都应该是十进制的。以下是一个 C 语言中格式说明符 %d 的示例,示例 在线演示 #include <stdio.h> int main() { int v1 = 7456; int v2 = -17346; printf("The value in decimal form : %d", v1); printf("The value in negative : %d", v2); return 0; } 输出 The value in decimal form : 7456 The value in negative : -17346 格式说明符 %i 格式说明符 %i 将整数作为整数来处理,这意味着… 阅读更多

C/C++ 中的 atol()、atoll() 和 atof() 函数

karthikeya Boyini
更新于 2020-06-24 11:18:30

625 次浏览

atol() 函数 atol() 函数将字符串转换为长整数。如果没有执行转换,则返回零。它返回转换后的长整数值。以下是 C++ 语言中 atol 的语法:long int atol(const char *string) 以下是一个 C++ 语言中 atol() 的示例,示例 在线演示 #include <iostream> using namespace std; int main() { long int a; char str[20] = "538756"; a = atol(str); cout<<

C++ 中的常成员函数

Samual Sam
更新于 2020-06-24 11:19:02

18K+ 次浏览

const 成员函数是在程序中声明为常量的函数。调用这些函数的对象不能被修改。建议使用 const 关键字,以避免意外更改对象。 const 成员函数可以被任何类型的对象调用。非 const 函数只能被非 const 对象调用。以下是 C++ 语言中 const 成员函数的语法:datatype function_name const(); 以下是一个 C++ 中 const 成员函数的示例,示例 在线演示 #include <iostream> using namespace std; class Demo { int val; public: Demo(int x = 0) { … 阅读更多

广告
© . All rights reserved.