栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > C++面试题库

C语言的字符串复制面试题

C语言的字符串复制面试题

题目如下:要求逆序输出输入的字符串,并且不能用第三方变量,

函数的原型是 char* strNCopy(const char* source,char* dest)

要求不用库函数

我写的程序如下:

#include #include char* strNCopy(const char* source,char* dest);

int main(int argc, char *argv[])

{ char* source=”1241654654″;

char dest[strlen(source)];

printf(“%dn”,strlen(dest));

strNCopy(source,dest);

printf(“%sn”,dest);

system(“PAUSE”);

return 0; } char* strNCopy(const char* source,char* dest) { if(source!=NULL&&dest!=NULL) { while(*++source) ; while(*dest++=*–source) ; return dest; } return NULL; }  以上代码看似实现了所要求的功能,但是没有判断dest的长度,没有考虑目标串能否容纳的下原字符串

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/265459.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号