English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Program has no error but when it run then doesn't give output... You ca check it.



#include
#include

int copy_file(char *Old, char *New);

int main (void)
{
char source[1024], destination[1024];

/*get source file name*/
printf("\nplease enter the source file name: ");
gets(source);
/*get destination file name*/
printf("\nplease enter the destination file name: ");
gets(destination);

/*check value returned by copy function, if any other*/
/*vlaue other than 0 is returned error message is displayed*/
if (copy_file(source, destination) ==0)
puts("File copy was successful");
else
fprintf(stderr, "Error trying to copy file!");

return 0;
}
int copy_file(char *Old, char *New)
{
FILE *fo, *fn;
int read, written;

/*open source file for reading in binary mode*/
/*if fopen gives a NULL character -1 is returned*/
/*main and error message displayed*/
if((fo=fopen(Old, "rb"))==NULL)
return -1;

/*open the destination file in binary writting mode*/
/*if fopen returns NULL source file is closed, the value*/
/*-1 is returned to main and error message is displayed*/
if((fn = fopen(New, "wb"))==NULL)
{
fclose(fo);
return -1;
}

/*read from source file in blocks of 1024, if the end of*/
/* the source file has not been reached, write the block to*/
/*the destination file.*/

while (1)
{
read = fread(Old, 1, 1024, fo);
getchar();
written = fwrite(Old, 1, read, fn);
getchar();

if(!feof(fo))
fputc(written, fn);
else
break;
}

fclose(fo);
fclose(fn);

return 0;

}

2006-12-03 05:52:37 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

1 answers

if i understand your question, you are asking how to make the program window stay open until you quit it, right?
if so, just add getchar() at the end of your main() right before your return 0 line.
if thats not what you are asking then be more specific. your question doesnt make much sense.

2006-12-04 01:02:23 · answer #1 · answered by justme 7 · 0 0

fedest.com, questions and answers