B
Bill Cunningham
your current problem seems almost identical to one I
gave a solution for. The only difference is the previous one
used fread/fwrite. I cannot comprehend how you can read my code
That's it right there. The ch you used I don't see all of what's going
on in your code. Basically I can't read it all.
Especially down around do.
and then post code that tries to copy a file ***without using a
loop construct***
***By Nick K.***
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf [2048];
FILE *fp_in;
FILE *fp_out;
size_t ch_read;
if ((fp_in = fopen ("as.exe", "rb")) == NULL)
{
fprintf (stderr, "failed to open input file\n");
exit (EXIT_FAILURE);
}
if ((fp_out = fopen ("a.exe", "wb")) == NULL)
{
fprintf (stderr, "failed to open output file\n");
fclose (fp_in);
exit (EXIT_FAILURE);
}
do
{
if ((ch_read = fread (buf, 1, sizeof(buf), fp_in)) !=
sizeof(buf)
&& ferror(fp_in))
{
fprintf (stderr, "read error\n");
fclose (fp_in);
fclose (fp_out);
exit (EXIT_FAILURE);
}
if (fwrite (buf, 1, ch_read, fp_out) != ch_read)
{
fprintf (stderr, "write error\n");
fclose (fp_in);
fclose (fp_out);
exit (EXIT_FAILURE);
}
}
while (ch_read == sizeof(buf));
fclose (fp_in);
fclose (fp_out);
return 0;
}
----
do
{
if ((ch_read = fread (buf, 1, sizeof(buf), fp_in)) !=
sizeof(buf)
&& ferror(fp_in))
{
Here's where I get lost.
Bill
gave a solution for. The only difference is the previous one
used fread/fwrite. I cannot comprehend how you can read my code
That's it right there. The ch you used I don't see all of what's going
on in your code. Basically I can't read it all.
Especially down around do.
and then post code that tries to copy a file ***without using a
loop construct***
***By Nick K.***
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char buf [2048];
FILE *fp_in;
FILE *fp_out;
size_t ch_read;
if ((fp_in = fopen ("as.exe", "rb")) == NULL)
{
fprintf (stderr, "failed to open input file\n");
exit (EXIT_FAILURE);
}
if ((fp_out = fopen ("a.exe", "wb")) == NULL)
{
fprintf (stderr, "failed to open output file\n");
fclose (fp_in);
exit (EXIT_FAILURE);
}
do
{
if ((ch_read = fread (buf, 1, sizeof(buf), fp_in)) !=
sizeof(buf)
&& ferror(fp_in))
{
fprintf (stderr, "read error\n");
fclose (fp_in);
fclose (fp_out);
exit (EXIT_FAILURE);
}
if (fwrite (buf, 1, ch_read, fp_out) != ch_read)
{
fprintf (stderr, "write error\n");
fclose (fp_in);
fclose (fp_out);
exit (EXIT_FAILURE);
}
}
while (ch_read == sizeof(buf));
fclose (fp_in);
fclose (fp_out);
return 0;
}
----
do
{
if ((ch_read = fread (buf, 1, sizeof(buf), fp_in)) !=
sizeof(buf)
&& ferror(fp_in))
{
Here's where I get lost.
Bill