//------------------------------------------------------------------ // This is a utility that will remove all the carriage returns // (ascii code 13--looks like ^M) from a file that was accidentally // uploaded using binary instead of ascii mode. // // usage: remcr // // Sample: // remcr addrspace.cc // ;now a file called addrspace.cc.fixed is made with no CRs // // To compile: gcc remcr.cc -o remcr // // Designed by Will Page and Ryan Cunningham for CSCI402 (c) 2003 // University of Southern California // Updated: 25.Feb.03 //------------------------------------------------------------------ #include #include int main(int argc, char **argv) { FILE *in, *out; char outname[100]; int errval = 0, inchar; argv++; // look at filename if(in = fopen(*argv,"r")) { strcpy(outname, *argv); strcat(outname, ".fixed"); // filename + .fixed if(out = fopen(outname, "w")) { inchar = fgetc(in); while(!feof(in)) { if(inchar != 13) fputc(inchar, out); inchar = fgetc(in); } } else { printf("ERROR: couldn't open %s for writing.\n",outname); errval = -2; } } else { printf("ERROR: couldn't open %s for reading.\n",*argv); errval = -1; } return errval; }