#include "IdanStringPointersLib.h" #include //--------------------------------------------------------------------------------------- // Highest CountTheLongestIdenticalCharacterSequence // ------------------------------------------------- // // General : The function checks the highest sequence of chars in a string // // Parameters : // *ptr_start - Pointer to a place in a vector(char) // // Return Value : Highest sequence // //--------------------------------------------------------------------------------------- unsigned short CountTheLongestIdenticalCharacterSequence(char * ptr_start) { unsigned short max_sum = ONE, temp_sum = ONE; ptr_start++; while (*(ptr_start++)) { if (*ptr_start != *(ptr_start - ONE)) { max_sum = (max_sum < temp_sum) ? temp_sum : max_sum; temp_sum = ZERO; } temp_sum++; } return (max_sum); } unsigned short IndexOfStringWithLongestIdenticalCharacterSequence(char *ptr_mat_start) { unsigned short max_sum = ZERO, temp_sum = ZERO, counter = ZERO, index = ZERO; unsigned int string_amount = (unsigned int)(ptr_mat_start) + (MAX_SIZE_STRING * TEN); for (counter = ZERO; (unsigned int)(ptr_mat_start) < string_amount; counter++) { temp_sum = CountTheLongestIdenticalCharacterSequence(ptr_mat_start); if (temp_sum > max_sum) { max_sum = temp_sum; index = counter; } ptr_mat_start += MAX_SIZE_STRING; } return (index); } //--------------------------------------------------------------------------------------- // EX #1 // ----- // // General : The program gets 10 strings and checks what string is with the highest // sequence of chars // // Input : 10 strings // // Process : The program runs on a string and checks what is the highest sequence than // it compares it to the max // // Output : the highest sequence in a the 10 strings // //--------------------------------------------------------------------------------------- // Programmer : Cohen Idan // Student No : 211675038 // Date: 19.11.2019 //--------------------------------------------------------------------------------------- void main(void) { typedef char string[MAX_SIZE_STRING]; string s1 = "aaaabbbbbccccccccccccccc\0"; string s2 = "aaaabbbbbccccvcccccccccc\0"; string s3 = "aaaabbbbbccccycccccccccc\0"; string s4 = "aaaabbbbbcccgccccccccccc\0"; string s5 = "aaaabbbbbccccckccccccccc\0"; string s6 = "aaaabbbbbccccchccccccccc\0"; string s7 = "aaaabbbbbccccncccccccccc\0"; string s8 = "aaaabbbbbccccjcccccccccc\0"; string s9 = "aaaabbbbbcccmccccccccccc\0"; string s10 = "aaaabbbbbccccucccccccccc\0"; string arr[10] = {*s5, *s2, *s3, *s4, *s1, *s6, *s7, *s8, *s9, *s10}; unsigned short max = PointerOfStringWithLongestIdenticalCharacterSequence(&arr[0]); printf("%hu\n", max); }