gpt4 book ai didi

关于选择我的函数版本的 C 编程

转载 作者:太空宇宙 更新时间:2023-11-04 06:05:49 24 4
gpt4 key购买 nike

在函数 main() 中{...}

1) #include头文件string.h

2) 我对自己的文件进行原型(prototype)制作,将其命名为 strcpy:

**char *strcpy(char *strSource , const char *dest);**

3) 我还希望在 main() 的 string.h 中使用“真正的”strlen 函数。

4) 在另一个编译文件中我有我的 strcpy 版本。

问题:如何让链接器选择我的 strcpy 版本而不是 string.h 中的原型(prototype)?

enter code here
#include <conio.h>
#include <string.h>
char *strcpy(char *source , const char *dest);
void main()
{
char *s, *d;
strcpy(s,d);
getch();
}

#include <stdio.h>
char *strcpy(char *strDestination, const char *strSource)
{
char *ptr;
printf("made it!");
return ptr;
}

最佳答案

你不能在 C 中这样做。这就是 C++ 引入命名空间的原因之一。

您唯一能做的就是为您自己的函数使用一个不冲突的名称。

关于关于选择我的函数版本的 C 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10805875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com