c 语言的字符串拷贝

danleiter 2015-04-16 02:27:19
想做c/c++程序员,写完了面试题,感觉都写了.
面试经理问,c 字符串拷贝函数用啥,我说strcpy
他说还有呢?我想了想说strncpy
他让我再想想,我实在想不出来了,毕竟没做过C程序员啊,不知道这些牛逼公司都咋写代码的.
他说你说的这些函数早就不用了,不安全.懂太少了,回去吧.
我郁闷啊.我中文版,英文版 都看了,书上是这么写的啊.难道string类说出来?那不c++了吗?
哎.
...全文
213 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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 不过这东西注意一下编译器警告就可以了,,,

70,023

社区成员

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

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