You had passed uninitialized ‘a’ value to scanf(), instead of address of variable ‘a’. So, scanf()
tried to write into wrong memory place and OS SIGSEGVed the your program. But if you pass address
of ‘a’ variable to scanf() (use ampersand to resolve address), the scanf() should correct fill in
the ‘a’ variable. So, if you meant the program (first version) was not SIGSEGVed for some reason
(can imagine it under DOS, but hardly under QNX), your output does not depend from input, because
uninitialized ‘a’ is still uninitialized ‘a’
Is your problem solved? BTW, it only scanf() needs address of variable, don’t use ampersand in
printf(), unless you want to print out the address.
Regards,
Eduard.
“ed1k” <ed1k@yahoo.com> wrote in message
news:01c1cc1e$b22c08c0$106fa8c0@ED1K…
Mario Charest <> goto@nothingness.com> > wrote in article
a6sp01$4f2$> 1@inn.qnx.com> >…
…
By the way main should always be declared as returning an int.
Is it demand of QNX? C doesn’t require the main() to be such spiteful >
“ed1k” <> ed1k@yahoo.com> > wrote in message
news:01c1cc1e$b22c08c0$106fa8c0@ED1K…
Mario Charest <> goto@nothingness.com> > wrote in article
a6sp01$4f2$> 1@inn.qnx.com> >…
…
By the way main should always be declared as returning an int.
Is it demand of QNX? C doesn’t require the main() to be such spiteful >
BTW, a programmed called test not producing the right output
under QNX4 is an old gotcha, as there is a test builtin command.
Best to call the final program something else.
In this case it wasn’t the problem, but be aware…
BTW, a programmed called test not producing the right output
under QNX4 is an old gotcha, as there is a test builtin command.
Best to call the final program something else.
In this case it wasn’t the problem, but be aware…
This is not particular to QNX, it is a feature of the shell. Almost all Unix
shells have a built-in called “test”.
On Fri, 15 Mar 2002 19:01:14 +0800, “ycao” <> ycao@mail.ipp.ac.cn> > wrote:
hi,
I have a programe test.c like below:
#include <stdio.h
void main()
{
int a;
scanf( “%d”, a );
printf("%d",a);
}
Then i use the command
cc test.c
then i execute the a.out and input 1 ,but the system give a message such as
:
a.out terminated(SIGSEGV) at :
%1 memory fault a.out
As someone said, you should probibly repost the source code. This is too
simple not to work. Although I have always found scanf() to be about the
crappiest function undcer ANY OS.
BTW, a programmed called test not producing the right output
under QNX4 is an old gotcha, as there is a test builtin command.
Best to call the final program something else.
In this case it wasn’t the problem, but be aware…
This is not particular to QNX, it is a feature of the shell. Almost all
Unix
shells have a built-in called “test”.
On Fri, 15 Mar 2002 19:01:14 +0800, “ycao” <> ycao@mail.ipp.ac.cn> > wrote:
hi,
I have a programe test.c like below:
#include <stdio.h
void main()
{
int a;
scanf( “%d”, a );
printf("%d",a);
}
Then i use the command
cc test.c
then i execute the a.out and input 1 ,but the system give a message
such as
:
a.out terminated(SIGSEGV) at :
%1 memory fault a.out