Friday, June 26, 2009

PROGRAM TO MERGE THE FILES SPLITTED BY THE PROGRAM BELOW

#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"

void main()
{
FILE *f1,*f2,*f3,*f4,*f5;
int i,n,m;
char *string;

f1=fopen("merged.txt","w");
f2=fopen("a.txt","r");
f3=fopen("b.txt","r");
f4=fopen("c.txt","r");
f5=fopen("d.txt","r");

fscanf(f2,"%[^\n]",string);
m=strlen(string);

n=4*m;


fclose(f2);
f2=fopen("a.txt","r");

for(i=0;i<(int)n/4;i++)
{
string[i]=fgetc(f2);
fputc(string[i],f1);
}
fclose(f2);

for(i=(int)n/4;i<(int)n/2;i++)
{
string[i]=fgetc(f3);
fputc(string[i],f1);
}
fclose(f3);

for(i=(int)n/2;i<(int)(3*n)/4;i++)
{
string[i]=fgetc(f4);
fputc(string[i],f1);
}
fclose(f4);

for(i=(int)(3*n)/4;i {
string[i]=fgetc(f5);
fputc(string[i],f1);
}


fclose(f5);
fclose(f1);
}

0 comments:


by Ankit Pokhrel.