write a program to copy one file to other file
Answers
Explanation:
import java.util.*;
class pattern1
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int i,c,j,d=1;
System.out.println("Press\n1. pattern 1\n2. pattern 2");
System.out.println("enter choice=");
c=sc.nextInt();
switch(c)
{
case 1: for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(d++);
System.out.println();
}
break;
case 2: for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
System.out.print(j%2);
System.out.println();
}
break;
default: System.out.println("wrong choice");
}
}
}
C program to copy contents of one file to another file
int main()
{
FILE *fptr1, *fptr2;
char filename[100], c;
printf("Enter the filename to open for reading \n");
scanf("%s", filename);
// Open one file for reading
fptr1 = fopen(filename, "r");
if (fptr1 == NULL)
{
printf("Cannot open file %s \n", filename);
exit(0);
}
printf("Enter the filename to open for writing \n");
scanf("%s", filename);
// Open another file for writing
fptr2 = fopen(filename, "w");
if (fptr2 == NULL)
{
printf("Cannot open file %s \n", filename);
exit(0);
}
// Read contents from file
c = fgetc(fptr1);
while (c != EOF)
{
fputc(c, fptr2);
c = fgetc(fptr1);
}
printf("\nContents copied to %s", filename);
fclose(fptr1);
fclose(fptr2);
return 0;
}
Output:
Enter the filename to open for reading
a.txt
Enter the filename to open for writing
b.txt
Contents copied to b.txt .
hopefully its helped u dear :)
(if my answer not relevant to ur question then u can report...thnku)
#keepsmiling❤✌