home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16387 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.7 KB  |  86 lines

  1. Newsgroups: comp.lang.c
  2. 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
  3. From: eager@eagercon.com (Michael J. Eager)
  4. Subject: Re: largest structure size on pc (in c)
  5. Message-ID: <1992Nov12.082431.20783@eagercon.com>
  6. Sender: root@eagercon.com (Operator)
  7. Reply-To: eager@eagercon.com
  8. Organization: Eager Consulting
  9. References: <92314.235722U17868@uicvm.uic.edu>
  10. Date: Thu, 12 Nov 1992 08:24:31 GMT
  11. Lines: 73
  12.  
  13. In article 235722U17868@uicvm.uic.edu, <U17868@uicvm.uic.edu> () writes:
  14. >my  program is listed below. it is very short. All I am trying to do is to
  15. >read from a file. But, I think the problem is that the structure size is too bi
  16. >g. It compiles successfully.I am using Turbo C 2.0. When I run it I get the mes
  17. >sage "Null Pointer Assignment". I tried different ways that is using malloc, wi
  18. >thout malloc, defining structure as a tag and then declaring an instance, but n
  19. >othing helpded. I have 2M RAM on my pc.Anyone has any suggestion send it to
  20. >u17868@uicvm..cc.uic.edu
  21. >
  22. >Thanks,
  23. >Sikander
  24. >===================my program ============================================
  25. >#include <stdio.h>
  26. >#include <stdlib.h>
  27. >struct {
  28. >    int  id;
  29. >    char  date[9];
  30. >    char day[10];
  31. >    int  stime;
  32. >    int  length;
  33. >    char location[10];
  34. >    char with_who[10];
  35. >    char phone[11];
  36. >    char subj[10];
  37. >    char note[10];
  38. >        int  flag;
  39. >}temp;
  40. >
  41. >main()
  42. >{
  43. >int i;
  44. >FILE *file_pointer;
  45. > file_pointer = fopen("activity.dat","rb+");
  46. > fseek(file_pointer,0,0);
  47. >
  48. > for(i=0;i<=4;i++)
  49. >     {
  50. >       scanf("%d",&temp.id);
  51. >       gets(temp.date);
  52. >       gets(temp.day);
  53. >       scanf("%d",&temp.stime);
  54. >       scanf("%d",&temp.length);
  55. >       gets(temp.location);
  56. >       gets(temp.with_who);
  57. >       gets(temp.phone);
  58. >       gets(temp.subj);
  59. >       gets(temp.note);
  60. >       scanf("%d",&temp.flag);
  61. >       fwrite(&temp,sizeof(temp),1,file_pointer);
  62. >       }
  63. > }
  64. >
  65.  
  66.  
  67. Your program looks OK, but you don't tell what you have as input.
  68.  
  69. Null pointer assignment means that somewhere you have a pointer with
  70. the value 0 which is dereferenced and a value stored.  It has nothing
  71. to do with the size of the structure (which is just fine) or with the
  72. amount of memory on your computer.
  73.  
  74. If you happen to read in more than 9 characters into temp.note, it will
  75. overwrite whatever follows (same is true for the other char arrays).  In
  76. this case, you stand a good chance of stepping on other data.
  77.  
  78. Does the file "activity.dat" exist?  If it does not, it will not be 
  79. created, and file_pointer will be NULL.  You do not check for this.
  80.  
  81. ---
  82. Michael J. Eager        Michael.Eager@eagercon.com
  83. Eager Consulting        (415) 325-8077 
  84. 1960 Park Boulevard, Palo Alto, CA 94306-1141
  85.  
  86.