#include <stdio.h>
#include <string.h>
int BruteForce(const char* text, const char* pattern) {
int tLen = strlen(text);
int pLen = strlen(pattern);
int index = -1;
int i , j ;
if (tLen == 0 || pLen == 0 || tLen < pLen) {
return index;
}
for (i = 0; i < tLen - pLen + 1; ++i) {
for (j = 0; j < pLen; ++j) {
if (text[i + j] != pattern[j]) {
break;
}
}
if (j == pLen) {
index = i;
break;
}
}
return index;
}
int main() {
const char* text = "Computer Science and Technology";
const char* pat1 = "CSAT";
const char* pat2 = "and";
const char* pat3 = " ";
printf("The index of \"%s\" in \"%s\" is %d\n", pat1, text, BruteForce(text, pat1));
printf("The index of \"%s\" in \"%s\" is %d\n", pat2, text, BruteForce(text, pat2));
printf("The index of \"%s\" in \"%s\" is %d\n", pat3, text, BruteForce(text, pat3));
printf("The index of \"%s\" in \"%s\" is %d\n", text, text, BruteForce(text, text));
return 0;
}