下面的代码有问题。
...
int anInteger;
...
//anInteger gets a value
...
int *anotherInteger;
label = (int *)malloc(sizeof(int));
strncpy(anotherInteger, anInteger, 40);
基本上我想做的是将值从一个整数复制到我为其分配内存的另一个整数。这可以在整数之间使用 strncpy 还是我需要另一个函数?
最佳答案
只是取消引用 anotherInteger
。
*anotherInteger = anInteger;
strncopy
用于字符串。
关于使用分配的内存将整数复制到整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25489260/