   Writing to file runtime error
  I get a "send error report" dialogue box when I run this code. It probably means I'm using undeclared memory somewhere(like in an array), but I don't see it.#include <iostream>#include <fstream>#include <string.h>using namespace std;struct MAPDATA{  char name[30];  char texPath[30];  int heightNum;  unsigned int *terrainHeights;};void write_file(char *filename, MAPDATA *map){ofstream fout;fout.open(filename, ios::binary);fout.write(map->name, sizeof(map->name));fout.write(map->texPath, sizeof(map->texPath));fout.write((char *)map->heightNum, sizeof(int));fout.write((char *)map->terrainHeights[0], sizeof(unsigned int));fout.write((char *)map->terrainHeights[1], sizeof(unsigned int));fout.close();}  int main(){    MAPDATA *map;    map = new MAPDATA;    strcpy(map->name, "DESERT");    strcpy(map->texPath, "C:/Hello");    map->heightNum = 2;    map->terrainHeights = new unsigned int[map->heightNum];   map->terrainHeights[0] = 2;    map->terrainHeights[1] = 5; write_file("hello.txt", map);   cin.get();    delete[] map->terrainHeights;    delete map;};
  If you run the program in the debugger, it will tell you exactly where it crashes and why.   ;  What does "An access violation(Segmentation Fault) raised in your program" mean?   ;  It means that that line was trying to access memory it never allocated, either because an uninitialized or null pointer was dereferenced, or because you tried to read/write beyond the end of an array.   ;  That's what I thought. It seems to have this error when it reaches the line that writes the integer. Do you see any problems with that line of code?   ;  ...or because you tried to interpret an unsigned int as a pointer and then tried to access memory at the address corresponding to whatever value the unsigned int had.Σnigma   ;  Yes, I do. But I'd like you to try and figure it out yourself. What are you passing as the first argument to write()? Is that a valid thing to pass in, given the parameters write() is expecting?EDIT: Hmph.   ;  fout.write((char *)map->terrainHeights[0], sizeof(unsigned int));fout.write((char *)map->terrainHeights[1], sizeof(unsigned int));change to >>>fout.write((char *) &(map->terrainHeights[0]) , sizeof(unsigned int));fout.write((char *) &(map->terrainHeights[1]) , sizeof(unsigned int));or to >>>>fout.write((char *) map->terrainHeights , sizeof(unsigned int));fout.write((char *) map->terrainHeights + 1 , sizeof(unsigned int));Would that fix it ? (I think that what enigma meant in its enigmatic post ;-) )Edit: aaaaah sorry did I ruin the fun ? -_-   ;  Ok, I didn't look at the bottom post, so I figured it out myself(i think) I added the '&' sign infront of the variables. I did this because before I was passing values to be converted into char pointers. Instead, I passed the memory address, then converted it into a char memory address. Is my explanation correct? By the way, thanks Sneftel, its more fun when you get to figure stuff out on your own. Thanks for the shove in the right direction :)   ;Quote:Original post by SneftelEDIT: Hmph.Sorry Sneftel [sad].Σnigma   