Guest claudiuhks Posted May 14, 2012 Posted May 14, 2012 trim va elimina impuritatile si spatiile libere unei propozitii proaspete citite dintr-un fisier! void trim( char *cInput ){ char *cOldInput = cInput, *cStart = cInput; while( *cStart == ' ' || *cStart == ' ' || *cStart == 'r' || *cStart == 'n' ) cStart++; if( cStart != cInput ) while( ( *cInput++ = *cStart++ ) != '0' ) /* do nothing */; cStart = cOldInput; cStart += strlen( cStart ) - 1; while( cStart >= cOldInput && ( *cStart == '0' || *cStart == ' ' || *cStart == 'r' || *cStart == 'n' || *cStart == ' ' ) ) cStart--; cStart++; *cStart = '0'; while( *cStart != '0' ) { if( *cStart == ';' ) { *cStart = '0'; break; } cStart++; }}
Guest claudiuhks Posted May 14, 2012 Posted May 14, 2012 Iata si un exemplu: int main( ){ FILE *fFile = fopen( "myfile.txt", "a+" ); char cLine[ 256 ]; while( !feof( fFile ) ) { fgets( cLine, 256, fFile ); trim( cLine ); printf( "%sn", cLine ); } return 1;}
Recommended Posts