Programmation Avancée en C


is_id.c

00001 #include <stdio.h>
00002 #include <ctype.h>
00003 #include <string.h>
00004 #include <stdbool.h> 
00005 
00006 int is_id(char * s) {
00007     static char * C_valid_id_chars =
00008         "abcdefghijklmnopqrstuvwxyz"
00009         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
00010         "0123456789_";
00011     if ((s == NULL) || (strspn(s, C_valid_id_chars) != strlen(s))) return false;
00012     return !isdigit(*s); 
00013 }
00014 
00015 int main()
00016 {
00017     char *tab[9] =  { "lim_sup.", "lim_inférieure", "__A_",  "name-1", 
00018                      "_SALAIRE_du_MOIS_", "2e_jour", "_", "i", "3" };
00019     size_t i;
00020     for (i=0; i < 9; i++) {
00021         printf("\"%s\" \t %d\n",tab[i],is_id(tab[i]));
00022     }
00023     return 0;
00024 }