Jump to content

[Tutorial] Functie customizata: trim


Recommended Posts

Guest claudiuhks
Posted

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

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;
}

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.