#include <stdio.h>
#include <stdlib.h>
void copyint(char *i,char** temp);
int main()
{
char* a="00313";
char* temp;
int inte;
temp=(char*)malloc(sizeof(char));
copyint(a,&temp);
inte=atoi(temp);
printf("%s\n",temp);
system("PAUSE");
free(temp);
}
void copyint(char *i,char** temp)
{
*temp=i;
}
最佳答案
没问题,所以第一眼就指出问题所在: - copyint 将单个字符复制到指向的内存中。 那么正在做什么:临时值为“0”,随机,随机......
'0',随机 random 由 atoi 解析 - 未定义,因为我们不知道该指针下的内容。 然后打印出来...
使用strlen malloc strcpy
序列代替
编辑:它不会编译,因为您将 (char*) 传递到接受 (char) 的函数中。 (copyint(a,&temp);
)
关于c - 我无法解决这个问题。当我编译时,编译器因为 free func 给出了一个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4645502/