패턴매칭에 대한 질문하나 올립니다
미투리
스트링에서 패턴인 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 자바질문에 올려서 옴김니다..;;
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655471 | 링 버퍼 구현된 소스 인데요.. 이해가 잘안되서요.. | 소심한녀자 | 2024-05-20 |
2655440 | test파일이 안 되요. (2) | 리라 | 2024-05-19 |
2655416 | 고수님들 도움이 절실합니다. (2) | 세리 | 2024-05-19 |
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |
2654881 | PID 모듈 검색 부분 질문합니다 . | 이름없음 | 2024-05-14 |
2654850 | 조건에 만족하는 다음 수를 찾고 싶습니다. | 초엘 | 2024-05-14 |
2654790 | 두파일간 byte단위 txt파일 복사 中 | 슬찬 | 2024-05-14 |
2654768 | 사전만들기 입니다. | 여우By | 2024-05-13 |