fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct Consigne
  5. {
  6. char nom[8];
  7. long valeur;
  8. };
  9.  
  10. // les consignes et leurs valeurs par défaut.
  11. Consigne consignes[] =
  12. {
  13. { "tem", 2000 },
  14. { "lum", 1000 },
  15. { "pow", 500 }
  16. };
  17.  
  18. int main()
  19. {
  20. char entree[] = "pow=5000";
  21.  
  22. Consigne consigne;
  23. if ( sscanf( entree, "%7[^ =]%*[ =]%ld", consigne.nom, &consigne.valeur ) == 2 )
  24. {
  25. bool consigneInconnue = true;
  26. for ( int i = 0; i < sizeof(consignes) / sizeof(Consigne); i++ )
  27. {
  28. if ( !strcmp( consignes[i].nom, consigne.nom ) )
  29. {
  30. consigneInconnue = false;
  31. consignes[i].valeur = consigne.valeur;
  32. printf( "Consigne \"%s\" modifiée à %ld.\n", consigne.nom, consigne.valeur );
  33. break;
  34. }
  35. }
  36. if ( consigneInconnue )
  37. {
  38. printf("Consigne \"%s\" inconnue.\n", consigne.nom );
  39. }
  40. }
  41. else
  42. {
  43. printf("Commande \"%s\" inconnue.\n", entree );
  44. }
  45.  
  46. return 0;
  47. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Consigne "pow" modifiée à 5000.