On Fri, 7 Sep 2001, Yann Forget wrote:

> > Prochaines �ch�ances:
> >    08 (pr�fixe 0 signifie octal)

Soit le petit programme, compilable avec:
   gcc -Wall octal.c -o octal

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv) {
   if (argc == 2) {
      int valeur;

      if (sscanf(argv[1], "%d", &valeur) == 1) {
         printf("Value %%d: %d.\n", valeur);

         if (sscanf(argv[1], "%i", &valeur) == 1) {
            printf("Value %%i: %i.\n", valeur);
            return 0;
         }
         else {
            fprintf(stderr,
                    "%s: some issue with your input at %%i.\n", argv[0]);
            return 1;
         }
         /* NOT REACHED */
      }
      else {
         fprintf(stderr, "%s: some issue with your input at %%d.\n", argv[0]);
         return 1;
      }
   }
   else {
      fprintf(stderr, "%s number\n%s: bad args.\n", argv[0], argv[0]);
      return 2;
   }

   /* NOT REACHED */
}

Exemples:

schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 0
Value %d: 0.
Value %i: 0.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 00
Value %d: 0.
Value %i: 0.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 01
Value %d: 1.
Value %i: 1.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 07
Value %d: 7.
Value %i: 7.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 08
Value %d: 8.
Value %i: 0.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 09
Value %d: 9.
Value %i: 0.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 10
Value %d: 10.
Value %i: 10.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal -1
Value %d: -1.
Value %i: -1.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 010
Value %d: 10.
Value %i: 8.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 011
Value %d: 11.
Value %i: 9.
schaefer@defian:~/work/NOT_IN_ANY_CVS/octal% ./octal 0x42
Value %d: 0.
Value %i: 66.

Donc, sous certaines conditions, l'ann�e exprim�e � deux chiffres peut
�tre mal interpr�t�e et 2008/2009 (aka 08/09) comprises comme 2000 (aka
00). 

Utilisons la date au format ISO (2001-09-08), elle a l'avantage de tenir
assez longtemps, et de ne pas �tre ambigu� (le tr�ma sur le u ou le e ?).

> >    2037 (31 bits)
> 
> J'esp�re qu'on utilisera plus que des machines 64 bits sous Linux
> � ce moment.  ;o)

On a aussi pens� en 1960 que jamais ces logiciels et machines ne seraient
utilis�s plus que 5 ans, `l'informatique allant tellement vite' ... 


--
http://www-internal.alphanet.ch/linux-leman/ avant de poser
une question. Ouais, pour se d�sabonner aussi.

Répondre à