ACP4_10

//BCA Support //www.bcasupport.xyz #include <stdio.h> void main() { FILE *fp1,*fp2; struct file{ int cno,bal; char actype[8]; }cdetails[4]={ {101,2000,"Savings"}, {102,5000,"Current"}, {103,3000,"Savings"}, {104,10000,"Current"} }; char ch; int a; clrscr(); fp1=fopen("file1.txt","w"); fp2=fopen("file2.txt","a+"); if((fp1||fp2)==NULL) { printf("\nError in handling file(s)."); getch(); exit(); } fprintf(fp1,"Customer No.\tAccount Type\tBalance\n"); fprintf(fp2,"Customer No.\tAccount Type\tBalance\n"); for(a=0;a<4;a++) { fprintf(fp1,"%d\t\t",cdetails[a].cno); fprintf(fp1,"%s\t\t",cdetails[a].actype); fprintf(fp1,"%d\n",cdetails[a].bal); fprintf(fp2,"%d\t\t",cdetails[a].cno); fprintf(fp2,"%s\t\t",cdetails[a].actype); fprintf(fp2,"%d\n",cdetails[a].bal); } printf("\nData copied to file1.txt successfully."); printf("\nContents of file1.txt appended to file2.txt successfully."); getch(); clrscr(); printf("\nContents of file2.txt :\n\n"); rewind(fp2); while(!feof(fp2)) { ch=fgetc(fp2); printf("%c",ch); } fcloseall(); getch(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.