我有一個C程序寫在UNIX上。我正在分段錯誤。我沒有得到我錯過的東西。任何人都可以請幫忙。C程序導致段錯誤
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
char* app_name = NULL;
char* pInFile = NULL;
int main(int argc, char *argv[])
{
char* arg0 = argv[0];
char* pdebug = "miecf";
char* pLogfile = NULL;
char* pUserid = NULL;
char* pOutFile = NULL;
int c;
while((c = getopt(argc, argv, ":a:d:i:l:u:o")) != EOF)
{
switch (c)
{
case 'a':
app_name = optarg;
break;
case 'd':
pdebug = optarg;
break;
case 'i':
pInFile = optarg;
break;
case 'l':
pLogfile = optarg;
break;
case 'u':
pUserid = optarg;
break;
case 'o':
pOutFile = optarg;
break;
default:
fprintf(stderr, "unknown option \'%c\'\n", optopt);
break;
} /* switch(c) */
} /* while(getopt()) */
printf("app_name is [%s]\n",app_name);
printf("pdebug is [%s]\n",pdebug);
printf("pInFile is [%s]\n",pInFile);
printf("pLogfile is [%s]\n",pLogfile);
printf("pUserid is [%s]\n",pUserid);
printf("pOutFile is [%s]\n",pOutFile);
return 0;
}
運行命令
-a test -d deimf -i input.txt -l log.txt -u [email protected] -o out.txt
輸出
app_name is [test]
pdebug is [deimf]
pInFile is [input.txt]
pLogfile is [log.txt]
pUserid is [[email protected]]
run[2]: 10448 Segmentation Fault(coredump)
DBX報告
program terminated by signal SEGV (no mapping at the fault address)
0xff232370: strlen+0x0050: ld [%o2], %o1
(dbx) where
=>[1] strlen(0x0, 0xfffffaf0, 0x0, 0xffbff1a8, 0x0, 0x2b), at 0xff232370
[2] _ndoprnt(0x10f77, 0xffbff26c, 0xffbfe8e9, 0x0, 0x0, 0x0), at 0xff29e4d4
[3] printf(0x10f68, 0x21100, 0x0, 0x2111e, 0xff3303d8, 0x14), at 0xff2a0680
[4] main(0xc, 0xffbff304, 0xffbff4ad, 0xffbff4b8, 0x0, 0xffffffff), at 0x10e8
-1:你在調試器中運行程序時,賽格發生故障定位? – 2011-06-03 13:49:21
@油,是的,我做過。我正在添加dbx報告 – 2011-06-03 13:51:29
好吧,那更像是它! -1刪除... – 2011-06-03 13:54:29