title: Segmentation fault error in C when trying to print to a file
body: <p>I created a function which is supposed to to get a binary tree in argument, a filename in user input and inside that file print the binary tree in order to be later converted into a picture via graphviz.</p>
  
  <p>The binary tree type provided is:</p>
  
  <pre><code>struct noeud_s;
  
  typedef struct noeud_s noeud;
  
  typedef noeud* arbre;
  
  struct noeud_s{
    char* valeur;
    arbre gauche;
    arbre droit;
  };
  </code></pre>
  
  <p>The 2 functions I created are:</p>
  
  <pre><code>void create_dot(arbre racine)
  {
    FILE *f;
    char file_name[100];
    printf ("Nom du fichier a creer (Ajouter .dot a la fin): ");
    scanf ("%s", file_name);
    printf("Name: %s\n", file_name);
    printf ("Creation du fichier dot\n");
    f = fopen(file_name, "w");
    if (f == NULL)
    {
      printf("NULL\n");
    }
    fprintf(f, "digigraph tree {\n");
    write_to_dot(f, racine);
    fprintf(f, "}");
    fclose(f);
  }
  
  void write_to_dot(FILE *f, arbre racine)
  {
    if (racine == NULL)
    {
      return;
    }
    if (racine != NULL)
    {
      fprintf(f, "%s -&gt; %s [label = \"non\"]\n", racine -&gt; valeur, racine -&gt; gauche -&gt; valeur);
      fprintf(f, "%s -&gt; %s [label = \"oui\"]\n", racine -&gt; valeur, racine -&gt; droit -&gt; valeur);
      write_to_dot(f, racine -&gt; gauche);
      write_to_dot(f, racine -&gt; droit);
    }
    return;
  }
  </code></pre>
  
  <p>As far as debugging goes, I have deducted that my segmentation fault happens inside the write_to_dot function. But because I can't properly handle gdb, I would like you to help me find my segmentation fault and explain it please.</p>