Bonjour,

j'ai essayé l'exemple d'un cours de c sur les tableaux de fonction

voila le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <tgmath.h>
#include <string.h>
 
double sin(double), cos(double), exp(double), log(double);
 
struct {
 
  char *nom;
  double (*fon)(double);
 
} table[] = {
  "sin", sin,
  "cos", cos,
  "exp", exp,
  "log", log };
 
#define NBF (sizeof table / sizeof table[0])
 
int main(int argc, char **argv)
{
  char nom[100];
  double nb = 0;
  int i = 0;
 
  while(1)
    {
      scanf("%s", nom);
      if(strcmp(nom, "fin") == 0) return 1;
      scanf("%lf", &nb);
 
      for(i = 0; i < NBF && strcmp(table[i].nom, nom) != 0; i++);
 
      if(i < NBF) printf("%f\n", (*table[i].fon)(nb));
      else printf("%s ? \n", nom);
    }
 
  return 0;
}
et les résultats de compilation :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
main2.c:5:8: erreur: expected identifier or(’ before ‘__extension__’
main2.c:13:3: attention : accolades manquantes autour de l'initialisation [-Wmissing-braces]
main2.c:13:3: attention : (near initialization for ‘table[0]) [-Wmissing-braces]
j'aimerais savoir pour quoi cela ne fonctionne pas.

Merci d'avance,