i have the following struct

typedef char * typos_stoixeiou;
typedef int  metritis;
typedef struct korifi *kdiktis   ;

struct korifi
{
typos_stoixeiou dedomena;
metritis counter;
int kleidi;
int arithmospaidiwn ;
korifi *a[100];
};

if i try this

for(int s=0;s<size;s++)
{
root->a[s] =  (kdiktis)malloc(sizeof(struct korifi));
root->a[s] = NULL;
}

and 'size' is bigger than 19 the programm crashes

any idea ?

You have two problems that I see.

The first is that you are using the struct tag without the struct keyword: korifi *a[100]; I think you meant to say this: kdiktis a[100]; The next problem is that you are throwing memory away:

root->a[s] = (kdiktis)malloc(sizeof(struct korifi));  // allocate big chunk of memory
root->a[s] = NULL;                                    // throw it away (memory leak)

Also, I don't understand Greek and online translators are particularly bad at handling words used in source code, so I have no clue whatsoever what you are trying to do. Please translate stuff into English before posting on an English forum...

Hope this helps.

thanks for the answer . Your comment about
kdiktis a[100]; really helped me.
My intension is to make a tree in which every node has 0-100 children and put some special kind of info in them. But i did not understand the memoty leak thing.

What you are doing is essentially this:

int main() {
  char *s;

  s = (char *)malloc( 1000 );
  s = NULL;

  // what happened to the 1000 characters?
  }

You allocated space on the heap, then you promptly threw away the address of the space you allocated. There is no way to get it again. The space is lost to you --at best until you end your program and at worst until you reboot.

Hope this helps.

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.