pointer & struct

jair bobys jair at ficc.uu.net
Sat Feb 4 03:15:49 AEST 1989


In article <7208 at pyr.gatech.EDU>, dvu at pyr.gatech.EDU (Dinh Vu) writes:
> I am learning C, and having difficulty with pointers, and structures
> [some text deleted]
> 	main()
> 	{
> 		struct abc *var;
> 
> 		var->x = 5;
> 		var->y = 10;
> 	}

The problem is that you never allocated a structure for your pointer to
point to.  Try:

    main()
    {
        struct abc
            *var,
            place;

        var = place;
        var->x = 5;
        var->y = 10;
    }

You were trying to assign values to nonexistent locations, hence the core
dump.     
-- 
+------------------------------------------------------------------------------+
|"One ring to bring them all		|	Jair Bobys	(713) 274-5201 |
| and in the darkness bind them."	|      uunet!ficc!jair jair at ficc.uu.net|
+------------------------------------------------------------------------------+



More information about the Comp.lang.c mailing list