struct PhaseShiftPin {
int _PSPpin_index; //PSP = Phase Shift Pin
int _PSPvalue;
char _PSPname[512];
};
struct PhaseShiftPin *_PhaseShiftPin[500000];
int p3int = 0;
strcpy ( _PhaseShiftPin[i]->_PSPvalue, p3int );
上面的代码只是我完整代码的一部分。
当我编译我的完整程序时,发生了一个错误 strcpy',使得没有整数的整数指针
在网上
strcpy ( _PhaseShiftPin[i]->_PSPvalue, p3int );
我尝试使用strncpy并按照本文中显示的方法编译后仍然无法通过,请引用这里的makes pointer from integer without a cast with strcpy。希望您可以指导我解决我的问题。
最佳答案
如果看一下strcpy的定义,您会看到
char *strcpy(char *dest, const char *src);
但是您的
_PhaseShiftPin[i]->_PSPvalue
是整数,而p3int
也是。你可以使用memcpy
void *memcpy(void *dest, const void *src, size_t n);
strcpy ( &(_PhaseShiftPin[i]->_PSPvalue), &(p3int), sizeof(p3int) );
或只是在评论中说
_PhaseShiftPin[i]->_PSPvalue = p3int;
如果您尝试将
p3int
复制到_PhaseShiftPin[i]->_PSPvalue
关于c - 错误 “' strcpy'使指针从整数开始而没有强制转换”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17803295/