/* http://www.mrwadlo.com */ #include //#include #include void showpercent(int percent); void createfilename(); int mark; int tot = 0; char inputfile[15]; char outputfile[15]; int main() { long i; long filesize; char sym; int percent; long start, end; char ext; long min0, sec0; long timeOrg, timeGoal, timeNew, time0; //time1, time2; FILE *fpREAD; FILE *fpWRITE; clrscr(); printf("\n WARNING: RESIZING FILES CAN MAKE A FILE UN-OPENABLE"); do { printf("\n Enter Filename Using 8.3 limit: "); scanf("%12s", &inputfile); if ( fopen(inputfile,"rb") ) break; else printf("\n %s <-- No Such File, Try Again!", inputfile); } while ( 1 ); createfilename(); printf(" Outputting to: %s", outputfile); fpREAD = fopen(inputfile,"rb"); do { printf("\n How many minutes is the original file: "); scanf("%ld", &min0); } while ( min0 < 0 ); do { printf(" How many seconds is the original file: "); scanf("%ld", &sec0); } while ( sec0 < 0 ); timeOrg = (min0 * 60) + sec0; do { printf("\n How many minutes is the goal file: "); scanf("%ld", &min0); } while ( min0 < 0 ); do { printf(" How many seconds is the goal file: "); scanf("%ld", &sec0); } while ( sec0 < 0 ); timeGoal = (min0 * 60) + sec0; do { printf(" "); for ( i=0 ; i<38 ; i++ ) printf("- "); fpWRITE = fopen("output.mp3","wb"); fseek(fpREAD, 0, SEEK_END); filesize = ftell(fpREAD); rewind(fpREAD); printf("\n %s Filesize = %ld\n", inputfile, filesize); printf(" %s Filelength = %ld:%ld\n", inputfile, timeOrg/60, timeOrg%60); do { printf(" How many bytes to delete from the start: "); scanf("%ld", &start); } while (start < 0 || start > filesize ); do { printf(" How many bytes to delete from the end: "); scanf("%ld", &end); } while (end < 0 || end > filesize - start ); fseek(fpREAD,0,SEEK_SET); //printf("deleting: %ld and %ld\n", start, end); printf(" "); percent = 0; for ( i=0 ; i < filesize - end ; i++ ) { fread(&sym, 1, 1, fpREAD); if ( i >= start ) { fwrite(&sym, 1, 1, fpWRITE); //printf("%c", sym); tot++; } if ( 100*i/filesize > percent ) { percent++; showpercent(percent); } } while (percent < 100 ) showpercent(++percent); printf("\n Done"); fclose(fpWRITE); ext = '?'; while ( kbhit() != 0 ) getch(); while ( ext != 'y' && ext != 'Y' && ext != 'n' && ext != 'N' ) { //printf("\ntot = %d\n", tot); printf("\n Would you like to Retry? Y/N "); ext = getch(); //scanf("%c",&ext); } if ( ext == 'y' || ext == 'Y' ) { do { printf("\n How many minutes is the new file: "); scanf("%ld", &min0); } while ( min0 < 0 ); do { printf(" How many seconds is the new file: "); scanf("%ld", &sec0); } while ( sec0 < 0 ); timeNew = (min0 * 60) + sec0; if ( timeOrg != timeNew ) { time0 = ((timeOrg - timeGoal) * ( start + end )) / (timeOrg - timeNew); time0 = time0 - start - end; } else { printf(" Predicted same times.\n"); time0 = 0; } printf(" Predicted next attempt (from original): Start: %ld End: %ld\n", start+time0,end); printf(" Predicted next attempt (from original): Start: %ld End: %ld\n", start,end+time0); } } while ( ext != 'n' && ext != 'N' ); fclose(fpREAD); return 0; } void showpercent(int percent) { if( percent % 2 == 0) { mark++; printf("#"); printf(" %3d%%", percent); printf("\b\b\b\b\b"); fflush(stdout); } } void createfilename() { int i; for ( i=0 ; i<13 ; i++ ) { if ( inputfile[i] == '.' ) break; else outputfile[i] = 'O'; } while ( i<13 && inputfile[i] != '\n') { outputfile[i] = inputfile[i]; i++; } }