Ok. As the title says I tried many times to simply write a program that rewrites a file to remove null characters. I confirmed with a hex editor that the file in question has tons on null characters, on average about 1 of every 2 characters in null. So my last attempt:
#include <stdlib.h>
#include <stdio.h>
int main()
{
FILE *f = fopen("main2.c","r");
FILE *t = fopen("temp","w");
int c;
int count = 0;
while((c = fgetc(f))!=EOF)
{
if(c)
{
fputc(c,t);
}
else
{
printf("null found\n");
}
}
fclose(f);
fclose(t);
FILE *n = fopen("main2.c","w");
FILE *w = fopen("temp","r");
while((c=fgetc(w))!=EOF)
{
fputc(c,n);
}
fclose(n);
fclose(w);
}
I though if nothing else this should work perfectly. Instead it spits out a file with chinese characters.
Sorry for being so stupid but I'm feeling impatient right now. I guess I would like to know what I did wrong, an a correct example, maybe a much more concise and faster answer. Thanks.