C_Algorithms 2.0.0
Documentation
Loading...
Searching...
No Matches
Functions
patternSearch.c File Reference
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "patternSearch.h"
Include dependency graph for patternSearch.c:

Go to the source code of this file.

Functions

uint32_t PatternSearch (char *text, char *pattern)
 PatSearch is a Function to search for specific patterns in a text. (Be aware that its case sensitive!)
 

Function Documentation

◆ PatternSearch()

uint32_t PatternSearch ( char * text,
char * pattern )

PatSearch is a Function to search for specific patterns in a text. (Be aware that its case sensitive!)

Parameters
textInput as a char array / as a string
patternInput as a char array / as a string
Returns
int returns the position of the match or -1 if no match was found

Definition at line 16 of file patternSearch.c.

17{
18 uint32_t t = strlen(text);
19 uint32_t p = strlen(pattern);
20
21 for (uint32_t i = 0; i < t - p; i++)
22 {
23 uint32_t j;
24 for (j = 0; j < p; j++)
25 if (text[i + j] != pattern[j])
26 break;
27
28 if (j == p)
29 return i + 1;
30 }
31 return -1;
32}

Referenced by FunctionCall().

Here is the caller graph for this function: