Mail Archives: djgpp/1993/08/27/04:13:51
> HI !
Hi !!!
> When I compiled hello.c, the compiler liked it. (gcc hello.c -o hello,
> I then typed aout2exe hello)
Are you sure you've got no warnings ??? (explanation follows...)
> Here is my program.
>
> #include <stdio.h>
> main() {
>
> int n;
>
> printf("Hello, world!\n");
>
> for (n = 0; n < 2; n++)
> printf("HI!\n");
>
> scanf("%d", n);
Aouch !!! : the mistake is here. Take a look on any C manual or scanf
prototype. Y'll see something like :
scanf(const char *format, parameters...);
and parameters must be POINTERS to variables, not the variabvles
themselves...
So the correct form is :
scanf("%d", &n); /* not the & : address-of operator */
>
> printf("%d", n);
>
> }
>
> But when I run the program by typeing hello I get:
>
> Hello, world!
> HI!
>
> HI!
>
> 34 { I then typed the number 34, no real reason }
>
> Segmentation violation in
> Page fault at eip=31ed
> Call frame traceback EIPS
> 0x00031ed
> 0x0002dfa
> 0x0000183
> 0x000010d
>
>
May this help you...
Bruno Hivert
e-mail : hivert AT grenet DOT fr standard : 81 66 69 99
p-mail : L.P.M.O. N.pers : 81 66 69 78
32, avenue de l'Observatoire fax : 81 66 69 98
25044 Besancon Cedex
- Raw text -