A voir également:
- Chaine de caractére ca ne marche pas lors de l'execution
- Caractère ascii - Guide
- Caractère spéciaux - Guide
- Recherche automatique des chaînes ne fonctionne pas - Guide
- Caractere speciaux - Guide
- Chaine tnt gratuite sur mobile - Guide
1 réponse
Comme il est dit dans la manpage de gets :
Never use gets(). Because it is impossible to tell without knowing the data
in advance how many characters gets() will read, and because gets() will con?
tinue to store characters past the end of the buffer, it is extremely danger?
ous to use. It has been used to break computer security. Use fgets()
instead.
Et strstr renvoie un char* on ne peux donc pas le stocker dans un int.
Exemple :
Never use gets(). Because it is impossible to tell without knowing the data
in advance how many characters gets() will read, and because gets() will con?
tinue to store characters past the end of the buffer, it is extremely danger?
ous to use. It has been used to break computer security. Use fgets()
instead.
Et strstr renvoie un char* on ne peux donc pas le stocker dans un int.
Exemple :
#include <stdio.h> #include <string.h> int main() { char *p; char ch1[10], ch2[10]; printf("Chaine 1 : "); fgets(ch1,10,stdin); printf("Chaine 2 : "); fgets(ch2,10,stdin); p = strstr(ch1,ch2); printf("Substring : %s\n", p); return 0; }
Il faut donc supprimer le '\n'.
J'ai donc corrigé le code :