01 ```c 02 /* 03 LevenshteinDistance + Fuzzy Search 04 05 Example Usage: 06 U8 *array[3] = {"Pineaple","Pineaapples","Pineapl"}; 07 "Match: %s\n", FuzzySearch(array, 3, "Pineapple"); 08 */ 09 10 #define MAX_I64 9223372036854775807; 11 #define STR_LEN 256 12 13 static U8 m[STR_LEN][STR_LEN]; 14 15 I64 LevenshteinDistance(U8 *s1, U8 *s2) { 16 I64 len_s1 = StrLen(s1); 17 I64 len_s2 = StrLen(s2); 18 I64 i, j; 19 20 // Initialize the first row and column of the matrix. 21 for(i=0; i<=len_s1; i++) { 22 m[i][0] = i; 23 } 24 25 for(j=0; j<=len_s2; j++) { 26 m[0][j] = j; 27 } 28 29 // Fill the rest of the matrix 30 for(i=1; i<=len_s1; i++) { 31 for(j=1; j<=len_s2; j++) { 32 I64 cost = s1[i-1] != s2[j-1]; // Cost of substitution. 33 I64 deletion = m[i-1][j] + 1; 34 I64 insertion = m[i][j-1] + 1; 35 I64 substitution = m[i-1][j-1] + cost; 36 37 // Choose the minimum cost operation. 38 I64 minCost = Min(Min(deletion, insertion), substitution); 39 m[i][j] = minCost; 40 } 41 } 42 43 // The minimum distance is the value at the bottom right corner of the matrix. 44 I64 minDistance = m[len_s1][len_s2]; 45 46 return minDistance; 47 } 48 49 U8* FuzzySearch(U8 **arr, I64 size, U8* target) { 50 // Initialize the closest match and the minimum distance. 51 U8* closestMatch; 52 I64 minDistance = MAX_I64; 53 I64 i; 54 55 // Iterate over each string in the array. 56 for(i = 0; i < size; i++) { 57 // Calculate the Levenshtein Distance between the string and the target. 58 I64 distance = LevenshteinDistance(arr[i], target); 59 60 // If the distance is less than the minimum distance, update the closest match and the minimum distance. 61 if (distance < minDistance) { 62 closestMatch = arr[i]; 63 minDistance = distance; 64 } 65 } 66 67 // Return the closest match. 68 return closestMatch; 69 } 70 ```