#include #include #include #include char* search(char* txt, char* word) { // TODO return NULL; } int expo(int d, int n, int q) { return 0; // TODO } int q = 683303; int d = 256; int convert(char* s, int m) { return 0; // TODO } char* rabin_karp(char* txt, char* word) { int m = strlen(word); int p = expo(d, m-1, q); int hword = 0; // TODO int hs = 0; // TODO int i = 0 ; while (true) { char c = txt[i+m] ; txt[i+m] = '\0'; // pour le strcmp if (hs == hword && strcmp(&txt[i], word) == 0) { txt[i+m] = c; return &txt[i]; } txt[i+m] = c; if (c == '\0') { return NULL; } // fin du txt // TODO : mise à jour de hs i++; } return NULL; } void test_naif(char* txt, char* word) { printf("\nTest de l'algo naïf~:\n"); char* res = search(txt,word); if (res != NULL) { printf("La chaîne suivante commence par %s : %s\n", word, res); } else { printf("Chaine %s non trouvée par l'algo naïf\n", word); } } void test_rk(char* txt, char* word) { printf("\nTest de Rabin Karp~:\n"); char* res = rabin_karp(txt,word); if (res != NULL) { printf("La chaîne suivante commence par %s : %s\n", word, res); } else { printf("Chaine %s non trouvée par Rabin Karp\n", word); } } int main() { char txt[] = "Vive la MPI !"; char word[] = "MPI"; printf("Ce test doit afficher 78559 : %d\n", convert(&txt[1],3)); test_naif(txt, word); test_rk(txt, word); }