>>281
>a[strlen(new)] = '\0';
new[strlen(new)] = '\0'; もしくは
new[strlen(new)-1] = '\0';

fopen() 直後のfgetは余計