当我运行以下分段错误时...目标是将 argv 数组复制到 allowdip 数组。
char *allowdip;
int *allowdipcount;
int main(int argc, char *argv)
{
int xer;
allowdipcount = argc;
for(xer=0; xer<allowdipcount; xer++) {
allowdip[xer]=argv[xer];
}
for(xir=0; xir<allowdipcount -1; xir++) {
printf("%s\n", allowdip[xir]);
}
exit(EXIT_SUCCESS);
}
关于我做错了什么的任何想法?
更新
谢谢,现在我的代码是:
char **allowdip;
int allowdipcount;
int main(int argc, char *argv)
{
int xer;
int xir;
allowdipcount = argc;
char **allowdip = malloc(allowdipcount * sizeof(char*));
for(xer=0; xer<argc; xer++) {
allowdip[xer]=argv[xer];
}
for(xir=1; xir<allowdipcount; xir++)
printf("%s\n", allowdip[xir]);
exit(EXIT_SUCCESS);
}
它返回:
testscript2.c:51: warning: assignment makes pointer from integer without a cast
第 51 行包含:
allowdip[xer]=argv[xer];