#include "IdanStringLib.h" #include "IdanLib.h" #include #define STRING_MAX_SIZE 256 #define A 'a' #define B 'b' //--------------------------------------------------------------------------------------- // CountStringSubStrings // ------------------------ // // General : Checks how many substring can u build with the string that you // get in the main string you got. // // Parameters : // text - string (char[]) // // Return value : How many substring can you build (unsigned int). // //--------------------------------------------------------------------------------------- // Programmer : Cohen Idan // Student No : 211675038 // Date : 04.10.2019 //--------------------------------------------------------------------------------------- unsigned short CountStringSubStrings(char text[], char a, char b) { unsigned short count = ZERO; unsigned short text_lenght = StringLenght(text); unsigned short temp_text_lenght; char temp_text[text_lenght]; unsigned short index_a; CopyString(temp_text, text, ZERO); while (CharInString(temp_text, a)) { index_a = IndexCharInString(temp_text, a) + ONE; temp_text_lenght = StringLenght(temp_text); CutString(temp_text, index_a, temp_text_lenght - index_a); count += CountCharInString(temp_text, b); } return (count); } //--------------------------------------------------------------------------------------- // Exercise 3 // ---------- // // General : The program checks how many substring can u build with the string that you // get in the main string you got. // // Input : String. // // Process : The program checks if there is a char like the start (char start) that the // program got, if there is it will check how many ends (char end) and just // add it too the counter. // // Output : How many substring can you build. // //--------------------------------------------------------------------------------------- // Programmer : Cohen Idan // Student No : 211675038 // Date : 04.11.2019 //--------------------------------------------------------------------------------------- void main(void) { typedef char string[STRING_MAX_SIZE]; string str1 = "ababbb"; printf("%u\n", CountStringSubStrings(str1, A, B)); }