当前位置: 技术问答>开机的时候这个错误提示是什么意思?
iis7站长之家
"段错误"是什么意思?
来源: 互联网 发布时间:2015-04-29
本文导语: 我在redhat 9.0 中写了下面一段程序: #include #include #include ...
我在redhat 9.0 中写了下面一段程序:
#include
#include
#include
int main( int argc , char * argv[] )
{
DIR *dp;
struct dirent *dirp;
if( argc != 2 )
{
printf("a single argument( the directory name ) is required");
}
if(( dp = opendir( argv[1] )) == NULL )
printf("can't open %s" , argv[1] );
while((dirp = (struct dirent *) read(dp)) != NULL )
printf("%sn" , dirp->d_name);
closedir(dp);
exit(0);
}
编译 : gcc -o ls2 ls2.c //正常
运行时( ./ls2 "路径名" ) 则产生 "段错误"
为什么?
谢谢
#include
#include
#include
int main( int argc , char * argv[] )
{
DIR *dp;
struct dirent *dirp;
if( argc != 2 )
{
printf("a single argument( the directory name ) is required");
}
if(( dp = opendir( argv[1] )) == NULL )
printf("can't open %s" , argv[1] );
while((dirp = (struct dirent *) read(dp)) != NULL )
printf("%sn" , dirp->d_name);
closedir(dp);
exit(0);
}
编译 : gcc -o ls2 ls2.c //正常
运行时( ./ls2 "路径名" ) 则产生 "段错误"
为什么?
谢谢
|
while((dirp = (struct dirent *) read(dp)) != NULL )
->
while((dirp = (struct dirent *) readdir(dp)) != NULL )
->
while((dirp = (struct dirent *) readdir(dp)) != NULL )