Ok this is my situation I have this header file:

struct dir
{
	char name[3];
	int root_dir;
	int has_children;
	int num_children;
	int offset_to_children[2];
	int offset_to_files[16];
};
struct files
{
	char name[5];
	int size;
	int offset_to_beginning;
	int has_fragment;
	int next_fragment;
};
struct fat
{
	int files; 
	int dirs; 
	struct dir *dir_array; 
	struct files *file_array; 
};

In my program if I want to access the struct fat member *dir_array or *file_array, given that this member are pointers to another struct how can I access this members from my main program? This is what I'm doing and it compiles:

fat *pfat;
pfat->dir_array->root_dir=0;

My doubt is if I'm doing it right. Can anybody clarify my doubt and point my to the right direction. Thanks!!!

That is the correct way to access the members, but you have to allocate memory for all those pointers. For example

fat *pfat = new fat;
pfat->dir_array = new dir;
pfat->file_array = new files;

Also, what do you want to store in the name member functions? If its supposed to hold a filename then you need to make more room for them because file names can be up to 225 characters!

Yes is for files names but is just for an example and to know it works. What do you mean that I have to allocate memory to the pointers? I'm confuse can you explain. Thanks

Since you don't know how to use pointers you might want to read this tutorial by DaWei, member at PFO

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.