패턴매칭에 대한 질문하나 올립니다
미투리
스트링에서 패턴인 threads가 발생하는 경우를 모두 찾아 발견된 위치를 출력함.
All of the threads of a process share the same address space and other resources, such as open files. Any alteration of a resource by one thread affects the environment of the other threads in the same process.
이문장에서 패턴 threads가 2번나오는데요 제가 코딩을 했습니다
#include string.h
int StringMatch(char *str, char *pat) {
int i, j, start_s = 0;
int s = strlen(str);
int p = strlen(pat);
for(i=0; is; i++) {
for(j=0, start_s=i; jp && str[start_s]==pat[j]; start_s++, j++);
if(j == p)return i;
}
return -1;
}
int main(int argc, char* argv[]) {
char str[] = {All of the threads of a process share the same address space and other resources, such as open files. Any alteration of a resource by one thread affects the environment of the other threads in the same process.};
char pat[] = {threads};
int matched_index;
matched_index = StringMatch(str, pat);
if(matched_index -1)printf(Maching Index is %d\n, matched_index);
else printf(No Maching Pattern\n);
}
라고 쳤습니다
이걸 실행하면 한번만 찾아내면 그인덱스값을 출력하고 끈나는데요
문장 끝까지 읽은후에 index값을 출력하게 하려면 어떠케 해야하나요
p.s 자바질문에 올려서 옴김니다..;;