How to solve "Segmentation fault" error in C : <p>I'm not a expert in C, in fact, I hate it, but I have to do this project in this lenguage for my university. Well, when I have gone to test my code, I had a surprise with this error, "Segmentation fault". I was looking for internet and reading people with the same problem and I couldn't solve it. </p>

<p>So, this is my code:</p>

<pre><code>typedef struct evento{
    char* tipo; //baja, alta o evento
    char* tema; //tema al que pertenece
    char* valor;
    int puerto;
    struct sockaddr_in *dir;
}evento;

int generar_evento(const char *tema, const char *valor) {

//Socket()

int sock;

sock = socket(AF_INET, SOCK_STREAM, 0);

if (sock &lt; 0){
perror("Error en socket() en Editor");
exit(1);
}

//Preparar mensaje

evento evt;
strcpy(evt.tipo, "evento");
strcpy(evt.tema, tema);
strcpy(evt.valor, valor);
</code></pre>

<p>The code follows but is not important because I was testing it and the error is in:</p>

<pre><code>evento evt;
strcpy(evt.tipo, "evento");
strcpy(evt.tema, tema);
strcpy(evt.valor, valor);
</code></pre>

<p>I need that the <code>generar_evento</code>'s parametres (<code>const char *tema, const char *valor</code>) be copied in a <code>struct evento</code> but when I tried to do it the error appered.</p>

<p>Thanks!</p>
