R..
R..

Reputation: 35

String Comparisons - C

I'm trying to write a string routine in C, and I keep hitting on the same issue.

In C, I have this string:

MAMAAMAAALJ

If I have this string:

AAA

How can I determine that AAA is inside of MAMAAMAAAJ?

Upvotes: 1

Views: 178

Answers (3)

ceth
ceth

Reputation: 45325

Boyer–Moore string search algorithm


C realization

Upvotes: 1

intgr
intgr

Reputation: 20496

strstr("MAMAAMAAAJ", "AAA");

returns the pointer to the occurrence of the search string, or NULL if not found

Upvotes: 1

wallyk
wallyk

Reputation: 57794

Many C runtime libraries contain the function strstr (const char *s1, const char *s2).

If s2 is within s1, it returns a pointer within s1 to the beginning of the substring, otherwise returns NULL.

Upvotes: 5

Related Questions