delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/08/27/04:13:51

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 <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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019