c 语言的字符串拷贝

danleiter 2015-04-16 02:27:19
想做c/c++程序员,写完了面试题,感觉都写了.
面试经理问,c 字符串拷贝函数用啥,我说strcpy
他说还有呢?我想了想说strncpy
他让我再想想,我实在想不出来了,毕竟没做过C程序员啊,不知道这些牛逼公司都咋写代码的.
他说你说的这些函数早就不用了,不安全.懂太少了,回去吧.
我郁闷啊.我中文版,英文版 都看了,书上是这么写的啊.难道string类说出来?那不c++了吗?
哎.
...全文
203 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-04-16
  • 打赏
  • 举报
回复
引用 7 楼 SEESEECN 的回复:
感觉这面试的有点装B的嫌疑
http://mil.cankaoxiaoxi.com/2015/0416/744272.shtml 对付有点装B嫌疑的面试官,你要比他更装B! “能装B方能镇装B,准备装才可能不必装,越不能装越可能挨装。”
danleiter 2015-04-16
  • 打赏
  • 举报
回复
赵老师,我那可是去面试啊.对方是做防火墙的.好想成功面试啊.,可惜. 另外谢谢zhangxiangDavaid 的提议,但现在c的公司字符串拷贝真的流行用memmove吗?那memcpy不更快吗?另外,我自己感觉这函数要使其安全的话,还得自己先设置一下条件啊. 还有刚查了有人推荐的一个非c标准的strlcpy. 哎,没进过正规军,自己还得继续努力啊! 再次感谢大家的回答!进不了正规军,我就当个好伪军吧!
赵4老师 2015-04-16
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
字符串那些事儿!http://blog.csdn.net/pizi0475/archive/2010/03/04/5346708.aspx
楼主试试反问面试官,你知道字符串有多少种常用的表示方法吗?
Minikinfish 2015-04-16
  • 打赏
  • 举报
回复
字符串拷贝函数用啥? 你可以说,直接用等于号就可以了,你又没问我是 浅拷贝 还是 深拷贝
SEESEECN 2015-04-16
  • 打赏
  • 举报
回复
感觉这面试的有点装B的嫌疑
苏叔叔 2015-04-16
  • 打赏
  • 举报
回复
可以试试memmove
danleiter 2015-04-16
  • 打赏
  • 举报
回复
赵老师,别这样好吗?
danleiter 2015-04-16
  • 打赏
  • 举报
回复
谢谢 jiht594的回答. 我也想到了strcpy_s ,但是我也想起了cplusplus论坛里面的老外有说I agree that for portability strcpy_s should be avoided.所以我就放弃了说这个函数. 哎,想进c/c++行业这么难啊. 再次感谢您的回答!
赵4老师 2015-04-16
  • 打赏
  • 举报
回复
赵4老师 2015-04-16
  • 打赏
  • 举报
回复
String Manipulation These routines operate on null-terminated single-byte character, wide-character, and multibyte-character strings. Use the buffer-manipulation routines, described in Buffer Manipulation, to work with character arrays that do not end with a null character. String-Manipulation Routines Routine Use _mbscoll, _mbsicoll, _mbsncoll, _mbsnicoll Compare two multibyte-character strings using multibyte code page information (_mbsicoll and _mbsnicoll are case-insensitive) _mbsdec, _strdec, _wcsdec Move string pointer back one character _mbsinc, _strinc, _wcsinc Advance string pointer by one character _mbslen Get number of multibyte characters in multibyte-character string; dependent upon OEM code page _mbsnbcat Append, at most, first n bytes of one multibyte-character string to another _mbsnbcmp Compare first n bytes of two multibyte-character strings _mbsnbcnt Return number of multibyte-character bytes within supplied character count _mbsnbcpy Copy n bytes of string _mbsnbicmp Compare n bytes of two multibyte-character strings, ignoring case _mbsnbset Set first n bytes of multibyte-character string to specified character _mbsnccnt Return number of multibyte characters within supplied byte count _mbsnextc, _strnextc, _wcsnextc Find next character in string _mbsninc. _strninc, _wcsninc Advance string pointer by n characters _mbsspnp, _strspnp, _wcsspnp Return pointer to first character in given string that is not in another given string _mbstrlen Get number of multibyte characters in multibyte-character string; locale-dependent sprintf, _stprintf Write formatted data to a string strcat, wcscat, _mbscat Append one string to another strchr, wcschr, _mbschr Find first occurrence of specified character in string strcmp, wcscmp, _mbscmp Compare two strings strcoll, wcscoll, _stricoll, _wcsicoll, _strncoll, _wcsncoll, _strnicoll, _wcsnicoll Compare two strings using current locale code page information (_stricoll, _wcsicoll, _strnicoll, and _wcsnicoll are case-insensitive) strcpy, wcscpy, _mbscpy Copy one string to another strcspn, wcscspn, _mbscspn, Find first occurrence of character from specified character set in string _strdup, _wcsdup, _mbsdup Duplicate string strerror Map error number to message string _strerror Map user-defined error message to string strftime, wcsftime Format date-and-time string _stricmp, _wcsicmp, _mbsicmp Compare two strings without regard to case strlen, wcslen, _mbslen, _mbstrlen Find length of string _strlwr, _wcslwr, _mbslwr Convert string to lowercase strncat, wcsncat, _mbsncat Append characters of string strncmp, wcsncmp, _mbsncmp Compare characters of two strings strncpy, wcsncpy, _mbsncpy Copy characters of one string to another _strnicmp, _wcsnicmp, _mbsnicmp Compare characters of two strings without regard to case _strnset, _wcsnset, _mbsnset Set first n characters of string to specified character strpbrk, wcspbrk, _mbspbrk Find first occurrence of character from one string in another string strrchr, wcsrchr,_mbsrchr Find last occurrence of given character in string _strrev, _wcsrev,_mbsrev Reverse string _strset, _wcsset, _mbsset Set all characters of string to specified character strspn, wcsspn, _mbsspn Find first substring from one string in another string strstr, wcsstr, _mbsstr Find first occurrence of specified string in another string strtok, wcstok, _mbstok Find next token in string _strupr, _wcsupr, _mbsupr Convert string to uppercase strxfrm, wcsxfrm Transform string into collated form based on locale-specific information vsprintf, _vstprint Write formatted output using a pointer to a list of arguments
jiht594 2015-04-16
  • 打赏
  • 举报
回复
微软的_s系列 eg: strcpy_s 不过这东西注意一下编译器警告就可以了,,,
目 录 序言 前言 第1章 程序设计与算法 1 1.1 程序设计语言的发展 1 1.2 C语言的特点 2 1.2.1 C语言是中级语言 2 1.2.2 C语言是结构化语言 3 1.2.3 C语言是程序员的语言 3 1.3 C语言的程序结构 4 1.3.1 基本程序结构 4 1.3.2 函数库和链接 6 1.3.3 开发一个C程序 7 1.3.4 C语言的关键字 7 1.4 算法 8 1.4.1 流程图与算法的结构化描述 9 1.4.2 用N-S图描述算法 12 1.4.3 用PAD图描述算法 13 第2章 数据类型、运算符和表达式 14 2.1 C语言的数据类型 14 2.2 常量与变量 15 2.2.1 标识符命名 15 2.2.2 常量 16 2.2.3 变量 16 2.3 整型数据 16 2.3.1 整型常量 16 2.3.2 整型变量 17 2.4 实型数据 18 2.4.1 实型常量 18 2.4.2 实型变量 18 2.5 字符型数据 19 2.5.1 字符常量 19 2.5.2 字符串常量 19 2.5.3 转义字符 20 2.5.4 符号常量 20 2.5.5 字符变量 21 2.6 运算符 22 2.6.1 算术运算符 22 2.6.2 自增和自减 22 2.6.3 关系和逻辑运算符 23 2.6.4 位操作符 24 2.6.5 ?操作符 26 2.6.6 逗号操作符 27 2.6.7 关于优先级的小结 27 2.7 表达式 28 2.7.1 表达式中的类型转换 28 2.7.2 构成符cast 29 2.7.3 空格与括号 29 2.7.4 C语言中的简写形式 29 第3章 程序控制语句 31 3.1 程序的三种基本结构 31 3.2 数据的输入与输出 31 3.2.1 scanf()函数 31 3.2.2 printf()函数 33 3.2.3 getchar()函数与putchar()函数 36 3.2.4 程序应用举例 37 3.3 条件控制语句 38 3.3.1 if 语句 38 3.3.2 switch 语句 43 3.3.3 程序应用举例 45 3.4 循环控制语句 46 3.4.1 while语句 47 3.4.2 do... while 语句 49 3.4.3 for 语句 50 3.4.4 break与continue语句 53 3.4.5 程序应用举例 54 第4章 函数 57 4.1 函数说明与返回值 57 4.1.1 函数的类型说明 57 4.1.2 返回语句 58 4.2 函数的作用域规则 60 4.2.1 局部变量 60 4.2.2 全局变量 61 4.2.3 动态存储变量 62 4.2.4 静态存储变量 63 4.3 函数的调用与参数 63 4.3.1 形式参数与实际参数 64 4.3.2 赋值调用与引用调用 64 4.4 递归 64 4.5 实现问题 66 4.5.1 参数和通用函数 66 4.5.2 效率 66 4.6 函数库和文件 67 4.6.1 程序文件的大小 67 4.6.2 分类组织文件 67 4.6.3 函数库 67 4.7 C语言的预处理程序与注释 67 4.7.1 C语言的预处理程序 68 4.7.2 #define 68 4.7.3 #error 69 4.7.4 # include 69 4.7.5 条件编译命令 70 4.7.6 #undef 72 4.7.7 #line 73 4.7.8 #pragma 73 4.7.9 预定义的宏名 73 4.7.10 注释 73 4.8 程序应用举例 74 第5章 数组 78 5.1 一维数组 78 5.1.1 向函数传递一维数组 78 5.1.2 字符串使用的一维数组 79 5.2 二维数组 80 5.2.1 二维数组的一般形式 80 5.2.2 字符串数组 84 5.3 多维数组 85 5.4 数组的初始化 85 5.4.1 数组初始化 85 5.4.2 变长数组的初始化 86 5.5 应用程序举例 87 第6章 指针 91 6.1 指针与指针变量 91 6.2 指针变量的定义与引用 92 6.2.1 指针变量的定义 92 6.2.2 指针变量的引用 93 6.3 指针运算符与指针表达式 94 6.3.1 指针运算符与指针表达式 94 6.3.2 指针变量作函数的参数 95 6.4 指针与数组 96 6.4.1 指针与一维数组 97 6.4.2 指针与二维数组 99 6.4.3 数组指针作函数的参数 102 6.4.4 指针与字符数组 108 6.5 指针的地址分配 111 6.6 指针数组 112 6.7 指向指针的指针 118 6.8 main函数的参数 121 第7章 结构体与共用体 125 7.1 结构体类型变量的定义和引用 125 7.1.1 结构体类型变量的定义 126 7.1.2 结构体类型变量的引用 127 7.1.3 结构体类型变量的初始化 127 7.2 结构体数组的定义和引用 129 7.3 结构体指针的定义和引用 135 7.3.1 指向结构体类型变量的使用 135 7.3.2 指向结构体类型数组的指针的 使用 136 7.4 链表的建立、插入和删除 138 7.4.1 单链表 139 7.4.2 单链表的插入与删除 141 7.5 共用体 149 7.5.1 共用体的定义 149 7.5.2 共用体变量的引用 150 第8章 输入、输出和文件系统 153 8.1 缓冲文件系统 153 8.1.1 文件的打开与关闭 153 8.1.2 文件的读写 155 8.1.3 随机读写文件 163 8.2 非缓冲文件系统 166 8.3 文件系统应用举例 167 第9章 实用编程技巧 170 9.1 图形应用技巧 170 9.1.1 显示适配器类型的自动测试 170 9.1.2 屏幕图像的存取技巧 179 9.1.3 屏幕显示格式的控制方法 181 9.1.4 使图形软件脱离BGI的方法 182 9.1.5 拷贝屏幕图形的方法 183 9.1.6 随意改变VGA显示器显示颜色的 技巧 185 9.1.7 用随机函数实现动画的技巧 187 9.1.8 用putimage 函数实现动画的技巧 189 9.2 菜单设计技术 191 9.2.1 下拉式菜单的设计 191 9.2.2 选择式菜单的设计 194 9.2.3 实现阴影窗口的技巧 195 9.3 音响技巧 197 9.3.1 音乐程序设计 197 9.3.2 自动识谱音乐程序 200 9.3.3 实现后台演奏音乐的技巧 203 第10章 C++入门 205 10.1 面向对象的概念 205 10.1.1 面向对象的程序结构 205 10.1.2 C++的类 206 10.2 C++的输入与输出 207 10.3 类与对象 208 10.3.1 类的定义与对象的引用 209 10.3.2 构造函数与析构函数 211 10.3.3 函数重载 215 10.3.4 友元 216 10.4 对象指针 219 10.5 派生类与继承类 225 10.5.1 单继承的派生类 225 10.5.2 多继承的派生类 233 附录A 常用字符与ASCII代码对照表 238 附录B 习题 239

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧