b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

strchr函数php_c++ strchr函数_模拟实现strchr函数(2)

电脑杂谈  发布时间:2017-02-21 09:19:16  来源:网络整理

strncpy(char destination[], const char source[], int numchars);strncpy:将字符串source中前numchars个字符拷贝到字符串destination中。

strncpy函数应用举例原型:strncpy(char destination[], const char source[], int numchars);功能:将字符串source中前numchars个字符拷贝到字符串destination中例程:#include <iostream.h> #include <string.h> void main(void)

{ char str1[10] = { "Tsinghua "};char str2[10] = { "Computer"};cout <<strncpy(str1,str2,3)<<endl;}运行结果:Comnghua注意:字符串source中前numchars个字符将覆盖掉字符串destination中前numchars个字符!

strcat(char target[], const char source[]);strcat:将字符串source接到字符串target的后面。

strcat函数应用举例原型:strcat(char target[], const char source[]);功能:将字符串source接到字符串target的后面例程:#include <iostream.h> #include <string.h> void main(void)

{ char str1[] = { "Tsinghua "};char str2[] = { "Computer"};cout <<strcpy(str1,str2)<<endl;}运行结果:Tsinghua Computer注意:在定义字符数组1的长度时应该考虑字符数组2的长度,因为连接后新字符串的长度为两个字符串长度之和。进行字符串连接后,字符串1的结尾符将自动被去掉,在结尾串末尾保留新字符串后面一个结尾符。

strncat(char target[], const char source[], int numchars);strncat:将字符串source的前numchars个字符接到字符串target的后面。

strncat函数应用举例:原型:strncat(char target[], const char source[], int numchars);功能:将字符串source的前numchars个字符接到字符串target的后面例程:#include <iostream.h> #include <string.h> void main(void)

{ char str1[] = { "Tsinghua "};char str2[] = { "Computer"};cout <<strncat(str1,str2,3)<<endl;}运行结果:Tsinghua Com

int strcmp(const char firststring[], const char secondstring);strcmp:比较两个字符串firststring和secondstring. strcmp函数应用举例原型:int strcmp(const char firststring[], const char secondstring);功能:比较两个字符串firststring和secondstring例程:#include <iostream.h> #include <string.h> void main(void)


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-33642-2.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...