找到 34423 篇文章 编程

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

karthikeya Boyini
更新于 2020年6月24日 11:27:03

6K+ 阅读量

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

C 中 fflush(stdin) 的用法

Samual Sam
更新于 2020年6月24日 11:27:30

7K+ 阅读量

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

C 中的 ispunct()

karthikeya Boyini
更新于 2020年6月24日 11:28:00

96 阅读量

函数 ispunct() 用于检查传递的字符是否为标点符号。如果它不是标点符号,则返回零,否则返回非零值。以下是 C 语言中 ispunct() 的语法:int ispunct(int character);以下是在 C 语言中使用 ispunct() 的示例:示例 实时演示#include #include 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年6月24日 11:28:22

153 阅读量

函数 strspn() 用于计算第一个字符串的子字符串的长度,该子字符串存在于第二个字符串中。它返回该子字符串的长度。以下是 C 语言中 strspn() 的语法:size_t strspn(const char *string1, const char *string2);以下是在 C 语言中使用 strspn() 的示例:示例 实时演示#include #include 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年6月24日 11:14:50

201 阅读量

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

C 中的 strpbrk()

Samual Sam
更新于 2020年6月24日 11:16:33

1K+ 阅读量

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

C 中的 scanf() 和 fscanf()

karthikeya Boyini
更新于 2020年6月24日 11:17:07

2K+ 阅读量

scanf() 函数函数 scanf() 用于在 C 语言中从 stdin 读取格式化输入。它返回写入其中的字符总数,否则返回负值。以下是 C 语言中 scanf() 的语法:int scanf(const char *characters_set)以下是在 C 语言中使用 scanf() 的示例:示例 实时演示#include 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年6月24日 11:17:57

2K+ 阅读量

格式说明符 %d格式说明符 %d 将整数作为带符号的十进制整数,这意味着值应该是十进制的,无论它是负数还是正数。以下是在 C 语言中使用格式说明符 %d 的示例:示例 实时演示#include 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年6月24日 11:18:30

625 阅读量

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

C++ 中的常成员函数

Samual Sam
更新于 2020年6月24日 11:19:02

18K+ 阅读量

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

广告

© . All rights reserved.