分段错误错误 [英] Segmentation fault error

查看:78
本文介绍了分段错误错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,在linux / gnu envirement中,下面的wrot测试文件看到

的第一个参数。

#include" stdio.h"

void main(int argc,char * argv [])

{

printf("%s",argv [0] [1]) ;

}

编译完成后,

$ ./test ww

分段错误


我无法解决问题。帮助,谢谢

I am newbie ,in linux/gnu envirement,wrot test file below to see the
first argument.
#include "stdio.h"
void main (int argc, char *argv[])
{
printf ("%s", argv[0][1]);
}
After compiled it,
$ ./test ww
Segmentation fault

I have no clue to work out. help , thanks

推荐答案

./ test ww

分段错误


我不知道如何解决问题。帮助,谢谢
./test ww
Segmentation fault

I have no clue to work out. help , thanks


文章< 68 *************************** ******* @ x29g2000prd。 googlegroups.com>,

< en ******* @ gmail.comwrote:
In article <68**********************************@x29g2000prd. googlegroups.com>,
<en*******@gmail.comwrote:

>我是新手,在linux / gnu envirement中,下面的wrot测试文件看到
第一个参数。
#include" stdio.h"
void main(int argc,char * argv [])
>I am newbie ,in linux/gnu envirement,wrot test file below to see the
first argument.
#include "stdio.h"
void main (int argc, char *argv[])



查看 http:/ /www.comeaucomputing.com/techtalk/#voidmain


> {

printf("%s", argv [0] [1]);
}
编译后,
>{
printf ("%s", argv[0][1]);
}
After compiled it,


./ test ww
分段错误
我不知道如何解决问题。帮助,谢谢
./test ww
Segmentation fault

I have no clue to work out. help , thanks



argv [0]指向ww

argv [0] [1]是''w'' (第二个)


因此,你正在尝试将char''w'的值传递给%s。

不知道什么你想做,但可能你试着做其中一个:


printf("%s",argv [0]);

printf ("%c",argv [0] [1]);

-

Greg Comeau / 4.3.10.1,C ++ 0xisms现在处于测试阶段!

Comeau C / C ++ ONLINE == http://www.comeaucomputing。 com / tryitout

世界级编译器:令人惊叹的C ++,惊人的C99,很棒的C90。

Comeau C / C ++与Dinkumware的库...有你试过了吗?

argv[0] points to "ww"
argv[0][1] is ''w'' (the second one)

Therefore, you''re trying the pass the value of the char ''w'' to %s.
Dunno what you want to do but probably you were try to do one of these:

printf ("%s", argv[0]);
printf ("%c", argv[0][1]);
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE == http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware''s Libraries... Have you tried it?


这篇关于分段错误错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆