1) You are adding 13 bytes for every match you make but you are not tracking that you are staying in bounds of your strings.
2) The bruteForce for(start3 =... loop will not nul terminate text2. You stop copying when you hit a nul.
3) You have a lot of off-by-one errors, for example, when you are filling in textCOOL.
The idiom used in C for iterating over a string is:
for (i = 0; i < stringlength; i++)
Unless you actually mean to iterate over the nul
4) bruteForce should return an int but is not returning anything. You probably meant to return p
5) You should remove unused variables. It will help clarify your code.
6) You should free() the RAM you malloc() when you are done using it
7) It would be nicer to mark the text and pattern parameters as const and return a pointer to your malloc()ed string (NULL on no match)
8) In main() char text2 is assigned to malloc(). j is not a pointer and should not be assigned to malloc. that variable is never used again. Just delete it.
9) Be nice to your future self. Find more descriptive names than text$NUMBER
You are probably over-writing the nul-terminator of text2 in bruteForce and then when you strcpy() your results into text you are going to get whatever garbage data exists in RAM up until you are lucky enough to hit a 0 value. You seem to have file paths there.
EDIT:
Each time you have a match you copy the start of text into text2 up to the pattern match.
for (start1 = 0; start1 < i; start1++) {
text2[start1]=text[start1];
}
Instead you need another variable to track where you are inside the destination string.
int dest = 0;
for (i = 0; i <= stringlength - patternlength; i++) {
...
for(start1 = i-patternlength; start1 < i; start1++){
text2[dest]=text[start1];
}
dest += sprintf(&text2[dest], "<mark>%s</mark>", pattern);
printf("%s",text2);
...
}
Cheers