I'm having problems with array of struct. I'm trying to copy a part of a string to an element of an array of struct. (sorry if it does not sound so clear)
here is my code
#include <stdio.h>
#include <string.h>
struct dict {
char key[1024];
char value[16384];
int level;
};
int main()
{
struct dict entry[2562];
char str[]="i will finish my mp";
int j=0;
int i = 0;
char temp[1024];
char a =0;
while(a != 'h' ){
a = str[i];
temp[i] = str[i];
i++;
}
strcpy(entry[0].value,str);
puts(entry[0].value);
return 0;
}
It compiles but it does segmentation fault and I don't know what's wrong with it please help
struct dict entry[2562];is possibly a bit too big to fit in automatic storage ("on the stack") Make it global, or allocate dynamically.struct dict entry[2562]on the stack. Try moving it out of the function and see if it works.