词条 | strnset |
释义 | 函数名: strnset 功 能: 将一个串中的所有字符都设为指定字符 用 法: char *strnset(char *str, char ch, unsigned n); 程序例: #include <stdio.h> #include <string.h> int main(void) { char string[55] = "abcdefghijklmnopqrstuvwxyz"; char letter = 'x'; printf("string before strnset: %s\", string); strnset(string, letter, 13); printf("string after strnset: %s\", string); return 0; } 注意 不能 写 char *string = "abcdefghijklmnopqrstuvwxyz"; 然后调用strnset(string, letter, 13); 因为这里string 指向的是常量区“abcdefghijklmnopqrstuvwxyz”的地址 是不能再被更改指向的内容的。 很多C函数介绍的 例子里面都有这个问题 希望我们都注意。 学习happy。 |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。