F
FrancisC
#include <stdio.h>
int file_copy( char *oldname, char *newname );
int main()
{
char source[80], destination[80];
printf("\nEnter source file: ");
gets(source);
printf("\nEnter destination file: ");
gets(destination);
if ( file_copy(source, destination )==0 )
puts("Copy operation successful");
else
fprintf(stderr, "Error during copy operation");
system("PAUSE");
return(0);
}
int file_copy( char *oldname, char *newname)
{
FILE *fold, *fnew;
int c;
char tempString[150];
if ( ( fold = fopen( oldname, "r")) == NULL)
{
printf("Source file is not open\n");
return -1;
}
if ((fnew = fopen(newname, "w")) == NULL)
{
printf("Destination file is not open\n");
fclose(fold);
return -1;
}
while(1)
{
/* I want to ignore a line */
fgets(tempString, 130, fold);
c=fgetc(fold);
if(!feof(fold))
fputc(c, fnew);
else
break;
}
fclose(fnew);
fclose(fold);
return 0;
}
In the above program, I want to open a file and copy to a new file.
The new file is the same as the old file except the first line is ignored
from the old file.
How can I do that?
The above program works well of just copying old file to new file if I
delete this line(which I want to ignore the first line but failed):
/* I want to ignore a line */
fgets(tempString, 130, fold);
how can I do that?
thx!!
int file_copy( char *oldname, char *newname );
int main()
{
char source[80], destination[80];
printf("\nEnter source file: ");
gets(source);
printf("\nEnter destination file: ");
gets(destination);
if ( file_copy(source, destination )==0 )
puts("Copy operation successful");
else
fprintf(stderr, "Error during copy operation");
system("PAUSE");
return(0);
}
int file_copy( char *oldname, char *newname)
{
FILE *fold, *fnew;
int c;
char tempString[150];
if ( ( fold = fopen( oldname, "r")) == NULL)
{
printf("Source file is not open\n");
return -1;
}
if ((fnew = fopen(newname, "w")) == NULL)
{
printf("Destination file is not open\n");
fclose(fold);
return -1;
}
while(1)
{
/* I want to ignore a line */
fgets(tempString, 130, fold);
c=fgetc(fold);
if(!feof(fold))
fputc(c, fnew);
else
break;
}
fclose(fnew);
fclose(fold);
return 0;
}
In the above program, I want to open a file and copy to a new file.
The new file is the same as the old file except the first line is ignored
from the old file.
How can I do that?
The above program works well of just copying old file to new file if I
delete this line(which I want to ignore the first line but failed):
/* I want to ignore a line */
fgets(tempString, 130, fold);
how can I do that?
thx!!