From: hivert AT cicg-calcul DOT grenet DOT fr Posted-Date: Fri, 27 Aug 1993 09:41:10 +22316520 (DFT) Subject: Re: your mail To: shipmanm AT cs DOT arizona DOT edu (Michael S Shipman) Date: Fri, 27 Aug 1993 09:41:10 +22316520 (DFT) Cc: djgpp AT sun DOT soe DOT clarkson DOT edu > 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 > 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