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
|
#include <stdio.h>
int main(){
char* Registre[32]={ "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8",
"R9", "R10", "R11", "R12", "R13", "R14", "R15", "R16", "R17", "R18", "R19",
"R20", "R21", "R22", "R23", "R24", "R25", "R26", "R27","R28", "R29", "R30",
"R31"};
char *chaine_recherchee = "R2";
int indice_recherche = recherche_indice(Registre,32,chaine_recherchee);
if(indice_recherche == -1){
printf("La chaine n'a pas ete trouvee\n");
}
else{
printf("La chaine est a l'indice : %i\n",indice_recherche);
}
return 0;
}
int recherche_indice(char **tab,int size, char *recherche){
int i;
for(i = 0; i < size; i++){
if(strcmp(tab[i],recherche) == 0){
return i;
}
}
return -1;
} |
Partager