Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'll say more about the DLL further down, but for a start, here is the layout of the source files you'll need to do that.</p> <p>You'll need three files: </p> <ul> <li>main.c </li> <li>kmp.h </li> <li>kmp.c. </li> </ul> <p>Code structure: </p> <p>File main.c</p> <pre><code>#include &lt;stdio.h&gt; #include "kmp.h" // this will make the kmp() function known to main() int main(int argc, const char *argv[]) { char target[200]; ... same code as you aready have } </code></pre> <p>File kmp.h</p> <pre><code>// prototype to make kmp() function known to external programs (via #include) extern int kmp(char *target, int tsize, char *pattern, int psize); </code></pre> <p>File kmp.c</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; // declare kmp prototype as DLL-export _declspec(dllexport) int kmp(char *target, int tsize, char *pattern, int psize); // prototype for internal helper function static int *compute_prefix_function(char *pattern, int psize); // // implementation of kmp() function (and helper) // int kmp(char *target, int tsize, char *pattern, int psize) { int i; ... same program code as you aready have } int *compute_prefix_function(char *pattern, int psize) { int k = -1; ... same program code as you aready have } </code></pre> <p>.</p> <p>Now, for a first step, you can make these three files, and compile them in your current project (i.e. split your current project source into those three files, just leave out the line in kmp where it says __declspec(dllexport) and compile as before (non-DLL) to see if all works).</p> <p>.</p> <p>You will then need to create a DLL project for kmp.h and kmp.c (that will compile a KMP.DLL and KMP.LIB). Then you create a normal program (like your current sample) with main.c and need to link it with KMP.LIB / KMP.DLL</p> <p>The following may be a bit fuzzy, because I only have VS2005 here, but the steps to create the DLL project should be essentially somewhat like this: </p> <ul> <li>new project: Type Win32 / Win32-Project</li> <li>name KMP</li> <li>in the wizard choose Type DLL and check "Empty Project"</li> <li>add your kmp.c and kmp.h files</li> </ul> <p>In your main project (the one with the main.c program), you can then do </p> <ul> <li>File Menu > Add > Existing Project > KMP.vcproj</li> </ul> <p>This will automatically build and link the DLL from with your main.c program project.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload