Skip to content

Instantly share code, notes, and snippets.

@idlecool
Created May 6, 2011 15:28
Show Gist options
  • Save idlecool/959157 to your computer and use it in GitHub Desktop.
Save idlecool/959157 to your computer and use it in GitHub Desktop.
Merge two corrupt files (one at front and another at rear) into one neat file.
#include <stdio.h>
void main()
{
FILE *ifp1, *ifp2, *ofp;
int limit, pointer=0;
int current_char, junkchar;
limit = 300*1024; // 300KB
ifp1 = fopen("eclipse-java-helios-SR2-linux-gtk2","r");
ifp2 = fopen("eclipse-java-helios-SR2-linux-gtk","r");
ofp = fopen("eclipse-java-helios-SR2-linux-gtk.tar.gz","w");
while(1)
{
if (pointer<limit)
{
current_char = fgetc(ifp1);
junkchar = fgetc(ifp2);
}
else
{
current_char = fgetc(ifp2);
}
if (current_char==EOF)
{
break;
}
fputc(current_char, ofp);
pointer++;
}
fclose(ifp1);
fclose(ifp2);
fclose(ofp);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment