home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!ditka!eagercon!eagercon!eager
- From: eager@eagercon.com (Michael J. Eager)
- Subject: Re: largest structure size on pc (in c)
- Message-ID: <1992Nov12.082431.20783@eagercon.com>
- Sender: root@eagercon.com (Operator)
- Reply-To: eager@eagercon.com
- Organization: Eager Consulting
- References: <92314.235722U17868@uicvm.uic.edu>
- Date: Thu, 12 Nov 1992 08:24:31 GMT
- Lines: 73
-
- In article 235722U17868@uicvm.uic.edu, <U17868@uicvm.uic.edu> () writes:
- >my program is listed below. it is very short. All I am trying to do is to
- >read from a file. But, I think the problem is that the structure size is too bi
- >g. It compiles successfully.I am using Turbo C 2.0. When I run it I get the mes
- >sage "Null Pointer Assignment". I tried different ways that is using malloc, wi
- >thout malloc, defining structure as a tag and then declaring an instance, but n
- >othing helpded. I have 2M RAM on my pc.Anyone has any suggestion send it to
- >u17868@uicvm..cc.uic.edu
- >
- >Thanks,
- >Sikander
- >===================my program ============================================
- >#include <stdio.h>
- >#include <stdlib.h>
- >struct {
- > int id;
- > char date[9];
- > char day[10];
- > int stime;
- > int length;
- > char location[10];
- > char with_who[10];
- > char phone[11];
- > char subj[10];
- > char note[10];
- > int flag;
- >}temp;
- >
- >main()
- >{
- >int i;
- >FILE *file_pointer;
- > file_pointer = fopen("activity.dat","rb+");
- > fseek(file_pointer,0,0);
- >
- > for(i=0;i<=4;i++)
- > {
- > scanf("%d",&temp.id);
- > gets(temp.date);
- > gets(temp.day);
- > scanf("%d",&temp.stime);
- > scanf("%d",&temp.length);
- > gets(temp.location);
- > gets(temp.with_who);
- > gets(temp.phone);
- > gets(temp.subj);
- > gets(temp.note);
- > scanf("%d",&temp.flag);
- > fwrite(&temp,sizeof(temp),1,file_pointer);
- > }
- > }
- >
-
-
- Your program looks OK, but you don't tell what you have as input.
-
- Null pointer assignment means that somewhere you have a pointer with
- the value 0 which is dereferenced and a value stored. It has nothing
- to do with the size of the structure (which is just fine) or with the
- amount of memory on your computer.
-
- If you happen to read in more than 9 characters into temp.note, it will
- overwrite whatever follows (same is true for the other char arrays). In
- this case, you stand a good chance of stepping on other data.
-
- Does the file "activity.dat" exist? If it does not, it will not be
- created, and file_pointer will be NULL. You do not check for this.
-
- ---
- Michael J. Eager Michael.Eager@eagercon.com
- Eager Consulting (415) 325-8077
- 1960 Park Boulevard, Palo Alto, CA 94306-1141
-
-