本文介绍了strcpy和strcat的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 为什么strcpy和strcat(以及某些非标准的实现中的strupr和strlwr)返回一个char *?当然这些逻辑(和DMA安全) )返回类型将无效? 谢谢, James McLaughlin。 解决方案 为什么strcat()返回一个void *,当它的两个参数都是 char *,并且函数被定义为处理字符串? strcpy()也是如此:为什么你认为它应该返回无效 *而不是char *? ISTM,因为两个函数 a)取char *作为参数(而不是void *), b)处理char *数据,并且 c)创建char *指针最好描述的结果, 两个函数/应该/返回char *指向它们已生成的结果的指针。 - - Lew Pitcher,IT专家,企业数据系统 企业技术解决方案,道明银行金融集团 (此处表达的意见是我自己的,不是我的意见雇主的) -----开始PGP签名----- V ersion:GnuPG v1.2.4(MingW32) iD8DBQFC5ickagVFX4UWr64RAmWKAJ9ymd + jL7wIqVGgrHNTo1 98BnxJDgCgrXyr BGAvh0N9wubb8W9NJLmfxIA = = 6TrQ -----结束PGP SIGNATURE ----- .... 为什么strcat()返回void *,当它们都是'的论点是 char *,函数被定义为处理字符串? 他说无效,不是无效*。并回答实际问题:我认为, 他们返回char *以允许这样的东西 返回strcat(strcpy(buf,path),file ); Jirka ... 为什么strcat()返回void *,当它们都是'的论点是 char *,函数被定义为处理字符串? 他说无效,不是无效*。并回答实际问题:我认为,他们返回char *以允许返回strcat(strcpy(buf,path),file); 此外,原本没有虚函数这样的东西吗? (我 知道我在没有无效的平台上工作。) - + ----- -------------------- + -------------------- + -------- --------------------- + | Kenneth J. Brody | www.hvcomputer.com | | | kenbrody / at\spamcop.net | www.fptech.com | #include< std_disclaimer.h> | + ------------------------- + -------------- ------ + ----------------------------- + 不要给我发电子邮件:< mailto:Th ************* @ gmail.com> Hi,Why do strcpy and strcat (and strupr and strlwr in some nonstandardimplementations) return a char*? Surely the logical (and DMA-safe))return type for these would have been void??Thanks,James McLaughlin. 解决方案Why should strcat() return a void *, when both of it''s arguments arechar *, and the function is defined as working on character strings?The same goes for strcpy(): why do you think that it should return void* rather than char *?ISTM that, since both functionsa) take char * as arguments (and not void *),b) work on char * data, andc) create results best described by char * pointers,both functions /should/ return char * pointers to the results that theyhave generated.- --Lew Pitcher, IT Specialist, Enterprise Data SystemsEnterprise Technology Solutions, TD Bank Financial Group(Opinions expressed here are my own, not my employer''s)-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.2.4 (MingW32)iD8DBQFC5ickagVFX4UWr64RAmWKAJ9ymd+jL7wIqVGgrHNTo1 98BnxJDgCgrXyrBGAvh0N9wubb8W9NJLmfxIA==6TrQ-----END PGP SIGNATURE-----.... Why should strcat() return a void *, when both of it''s arguments are char *, and the function is defined as working on character strings?He said void, not void *. And to answer the actual question: I think,they return char * to allow such things asreturn strcat(strcpy(buf, path), file);Jirka ... Why should strcat() return a void *, when both of it''s arguments are char *, and the function is defined as working on character strings? He said void, not void *. And to answer the actual question: I think, they return char * to allow such things as return strcat(strcpy(buf, path), file);Besides, wasn''t there originally no such thing as a void function? (Iknow I worked on platforms without "void".)--+-------------------------+--------------------+-----------------------------+| Kenneth J. Brody | www.hvcomputer.com | || kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |+-------------------------+--------------------+-----------------------------+Don''t e-mail me at: <mailto:Th*************@gmail.com> 这篇关于strcpy和strcat的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!