66 lines
2.3 KiB
C
66 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include "IdanStringPointersLib.h"
|
|
|
|
#define STRING_MAX_SIZE 256
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------
|
|
// CountStringBInStringA
|
|
// ---------------------
|
|
//
|
|
// General : Counting how many times stringB in stringA.
|
|
//
|
|
// Parameters :
|
|
// *start_string_a - Pointer of first string (char[])
|
|
// *start_string_b - Pointer of second string (char[])
|
|
//
|
|
// Return value : Count second string in first string (unsigned int).
|
|
//
|
|
//---------------------------------------------------------------------------------------
|
|
// Programmer : Cohen Idan
|
|
// Student No : 211675038
|
|
// Date : 12.11.19
|
|
//---------------------------------------------------------------------------------------
|
|
unsigned int CountStringBInStringA(char *start_string_a, char *start_string_b)
|
|
{
|
|
char *ptr_string_a_temp = start_string_a;
|
|
char temp = BACKSLASH_ZERO;
|
|
unsigned short count = ZERO;
|
|
unsigned short textB_lenght = StringLenght(start_string_b);
|
|
char *address = (ptr_string_a_temp + textB_lenght);
|
|
while (*(address - ONE))
|
|
{
|
|
SwapChars(&temp, address);
|
|
count += StringCompare(ptr_string_a_temp, start_string_b);
|
|
SwapChars(&temp, address);
|
|
address = ((++ptr_string_a_temp) + textB_lenght);
|
|
}
|
|
|
|
return (count);
|
|
}
|
|
|
|
//-----------------------------------------------------------------
|
|
// exe 1
|
|
// -----
|
|
// General : the program goes over the string and checks how many
|
|
// appearences the substring makes.
|
|
//
|
|
// Input : a string and a word/sub-string to search for.
|
|
//
|
|
// Process : the program takes the sub-string and checks if the
|
|
// string has the same sequence of chars in it.
|
|
//
|
|
// Output : The times it has shown up in the string.
|
|
//-----------------------------------------------------------------
|
|
// Proggramer : Cohen Idan
|
|
// Student No : 211675038
|
|
// Date : 12.11.19
|
|
//-----------------------------------------------------------------
|
|
void main(void)
|
|
{
|
|
char stringA[STRING_MAX_SIZE] = "aaaaaaaaaaaababbbbbbbbbab";
|
|
char stringB[STRING_MAX_SIZE] = "ab";
|
|
printf("Count: %d\n", CountStringBInStringA(&stringA[ZERO], &stringB[ZERO]));
|
|
|
|
} |