How to copy contents from one file to another word by word in C?
<p>I know how to copy contents from one file to another character by character, but I am supposed to do it word by word. I tried this code, but when I run this, my output file ends up having each word on a new line. How am I supposed to copy contents from one file to another (as is) word by word?</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main(int argc, char* argv[])
{
    // Error checking
    if(argc &lt; 3)
    {
        fprintf(stderr, "Please print two arguments");
        exit(EXIT_FAILURE);
    }

    char* input = argv[1];
    char* output = argv[2];
    char buffer[4096];

    FILE* fp_open = fopen(input, "r");
    if(fp_open == NULL) fprintf(stderr, "Unable to open input file");

    FILE* fp_write = fopen(output, "w");
    if(fp_write == NULL) fprintf(stderr, "Unable to open output file");

    while(fscanf(fp_open, "%s", buffer) == 1)
    {
        fprintf(fp_write,"%s\n", buffer);
    }

    fclose(fp_open);
    fclose(fp_write);

    return 0;
}
</code></pre>

<p>Note: I am only allowed to use <code>fscanf("%s")</code> for reading from an input file.</p>

<p>P.S. I also know that it is inefficient way to do it, but this is what I am supposed to do.</p>