coincé dans le tableau et la chaîne comparer avec strcmp c pourquoi ça marche? compilateur est resté coincé à if(strcmp(c,ch[i]) == 0){
coincé dans le tableau et la chaîne comparer avec strcmp c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char ch[]="asdfghjkl";
char c;
int n=sizeof(ch)/sizeof(char);
scanf("%c",&c);
for(int i=0;i<n;i++){
if(strcmp(c,ch[i]) == 0){
printf("%c is in %d\n",c,i+1);
break;
}else if(i==n-1){
printf("%c not fond\n",c);
}
}
return 0;
}
'strcmp' prend deux * chaînes * comme arguments. Vous passez un 'char' et une chaîne. Votre compilateur ne s'en plaint-il pas? Lire [Comment déboguer de petits programmes] (https://ericlippert.com/2014/03/05/how-to-debug-small-programs/). –
La fonction ['strcmp'] (http://en.cppreference.com/w/c/string/byte/strcmp) permet de comparer * les chaînes *. Vous voulez comparer * caractères *. –
le type de 'c' est' char' (un caractère, pas de chaîne). 'strcmp' nécessite' char * '. – BLUEPIXY