뜻 strstr를 는 것 라
strstr, strcase, strspn과 를 는 것다면 답 렸다.
strstr, strcase, strspn과 를 는 것다면 답 렸다.
~cpp #include <stdio.h> #include <stdlib.h> #include <string.h> #include <signal.h> // while 고기 귀다. while 무 루 돌리고 Ctrl-C를 료로 바꿔 끝내. void handler(int sig) { fprintf(stderr, "\n로그램 료다.\n"); exit(0); } // int main() { FILE *fp; char x[40] = "His teaching method is very good."; char buf[10]; char *loc; // signal handling struct sigaction act; act.sa_handler = handler; sigemptyset(&act.sa_mask); act.sa_flags = 0; sigaction(SIGINT, &act, 0); // if((fp = fopen("result.out", "w")) == NULL) fprintf(stderr, "fopen() error: result.out\n"), exit(-1); while(1){ fprintf(fp, "료 -> %s\n", x); fprintf(fp, " 문 -> "); printf(" 문 -> "); fgets(buf, sizeof(buf), stdin); // 문라고 space를 다. buf[strlen(buf)-1] = '\0'; // stream로 \n 다. fprintf(fp, "%s\n", buf); if((loc = strstr(x, buf)) == 0) fprintf(fp, "Not Found!\n"); else fprintf(fp, "first found -> %d\n", loc-x); fflush(fp); } fclose(fp); return 0; }
~cpp // result.out 료 -> His teaching method is very good. 문 -> method first found -> 13 료 -> His teaching method is very good. 문 -> test Not Found!