www.pudn.com > File_R&W.rar > File.cpp
#include#include #include int main() { FILE *fp = NULL, *fpNew = NULL; long l = 0; char* pstring = NULL, *pNewString = NULL; if( (fp = fopen( "e:\\a.txt", "r" )) != NULL ) { fseek(fp, 0, SEEK_END); l = ftell(fp); fseek(fp, 0, SEEK_SET); pstring = (char*)malloc(l); pNewString = (char*)malloc(l); fread(pstring, sizeof( char ), l, fp ); printf( "%s\n", pstring ); } else { printf( "Problem opening the file\n" ); return 0 ; } fpNew = fopen("e:\\b.txt", "w"); for(int i = 0; i < l; i++) { int j = 0; if((64 < (int)pstring[i] && (int)pstring[i] < 90 )|| (95 < (int)pstring[i] && (int)pstring[i] <123)) { pNewString[j] = pstring[i]; fwrite(pNewString, sizeof(char), 1, fpNew); } else if((int)pstring[i] == 32) { pNewString[j] = '\n'; fwrite(pNewString, sizeof(char), 1, fpNew); } } free(pstring); free(pNewString); return 0; }