/ Published in: C
Simple prog for removing trailing blanks. Not for use with binary, compressed, or encoded files. Please make backups of your files.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include <stdio.h> #include <stdlib.h> #include <windows.h> char*mytmpfile="notrail.tmp"; void err(char*text){ if(!text)text="Can't open file"; MessageBox( 0, text, "NoTrail Error", MB_ICONERROR | MB_OK ); } static inline void replace(char*s){ } static inline void notrail(char*filename){ FILE*i,*o; unsigned long int saved=0; unsigned long int n; int c; int b; if(!i)err(0); if(!o)err(0); do{ if(c==EOF)break; if(c==32){ n=1; if(c!='\n'&&c!=EOF){ while(--n); }else saved+=n; } b=c!=EOF; }while(b); if(saved){ char text[32]; n=MessageBox( 0, text, filename, MB_ICONASTERISK | MB_OKCANCEL ); if(n==IDOK){ replace(filename); return; } } } int main(int argc,char**argv){ if(argc<2){ MessageBox( 0, "Removes trailing blanks. To use, close this" " window and drag and drop one or more" " files onto the program's icon.", "NoTrail by Zufolek 2009", MB_ICONINFORMATION | MB_OK ); return 0; } while(--argc)notrail(*++argv); return 0; }