파일에서 불러온 문장을 각각 배열에 넣고 배열간에 문자 비교하는법 도와주세요

lhs8421478의 이미지

안녕하세요 C언어를 공부하는 청년입니다.

파일에서 문장을 받아와서 문장이 맞는지 비교를 하려고 합니다.

a라는 파일에서 문장을 받아와 a[255]라는곳에 저장을 하고
b라는 파일에서 문장을 받아와 b[255]라는곳에 저장을 합니다.

이때 a의 문장은 hahahahahahahahahahahe라고 하고
b의 문장은 he 라고 합니다.

두문장을 비교하고 a에서 b라는 문장이 나오면
he를 프린트 하게 하려고 하는데 어떻게 하면 좋을까요?? 설명 부탁 드립니다.

klyx의 이미지

lhs8421478의 이미지

pointer = strstr(a(배열), b(배열)) 이건 안되는건가요...??

지금 이런식으로해보고 있는데 계속 오류네요....

 26     library_file = fopen("library.txt","r");
 27     if (library_file == NULL) {
 28         printf("file open error\n");
 29         return 0;
 30     }
 31     while (!feof(library_file)) {
 32         fgets(library_buf, max_size, library_file);
 33         library_len = strlen(library_buf);
 34
 35         source_file = fopen(file_name,"r");
 36         if (source_file == NULL) {
 37             printf("file open error\n");
 38             return 0;
 39         }
 40         while (!feof(source_file)) {
 41             fgets(source_buf, max_size, source_file);
 42             check_pt = source_buf;
 43             source_len = strlen(check_pt);
 44             while (source_len > library_len) {
 45                 check_pt = strstr(source_buf, library_buf);
 46                 if (check_pt != NULL) {
 47                     printf("%s\n",check_pt);
 48                 } else {
 49                     continue;
 50                 }
 51                 check_pt = check_pt + library_len;
 52                 source_len = strlen(check_pt);
 53             }
 54         }
 55         fclose(source_file);
 56     }
 57     fclose(library_file);
 58 }

세그오류로 인해서 더이상 발전도 없고 더이상 모르겠습니다 ㅠㅠ 도움 부탁 드립니다.
klyx의 이미지

null-terminated 문자열이라면 아무거나 다 됩니다.
이걸론 뭐라고 할 수가 없네요.
앞에서 뭐가 어떻게 할당되있는지도 알 수 없고, 파일에 뭐가 들어있는지도 알 수 없으니까요.
컴파일 가능한 최소한의 코드, 예를 들면 본문에 적으거 처럼 배열 두개 놓고서 찾는 코드, 같은걸 작성해서 테스트를 해보세요.
그래도 문제가 생긴다면 그때 다시 올려보세요. 그래서 문제가 생기지 않는다면 strstr과 상관없거나 문자열 자체에 문제가 있다는거겠지요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.