Hi,
Based on your comments, let me modified the original question...
I want to create a struct with size of 4kb (this size is a requirement so I have to meet it). The problem was that I couldn't modify the value of the string variable contained in the struct because the compiler throws a segmentation fault. Currently, if I use a pointer to string instead of a string variable, I now know how to do it (thanks to you guys), however, I read that the way that I'm using to allocate the 4kb of memory (malloc) is not the best or the appropriate. If I use the "new" keyword, it dynamically allocates enough memory for the struct and it probably uses a different value than 4kb, right? and this is what I don't want.
I still have the doubt about why I could not modify the value of a string variable (not pointer) contained in my struct (something like paginas -> dato = "test"). It probably should be a consequence of the use of malloc
Anyway, I would really appreciate your advices about how to allocate the 4kb of memory.
The original code in c++ is the following:
#define TAM 4000
#define NUMPAGS 512
struct pagina
{
bitset<12> direccion;
char operacion;
char permiso;
string *dato; //I prefer to have a string variable
int numero;
};
void crearPagina(pagina* pag[], int pos, int dir)
{
pagina * paginas = (pagina*)malloc(sizeof(char) * TAM);
paginas -> direccion = bitset<12> (dir);
paginas -> operacion = 'n';
paginas -> permiso = 'n';
string **tempDato = &paginas -> dato;
char *temp = " ";
**tempDato = temp;
paginas -> numero = 0;
pag[pos] = paginas;
}
Thanks in advance!!!