Your call to strtok()
in incorrect. The second argument is a string or allowed token delimiters, which in your case a . If you call it with "DEL"
, it will overwrite the D
with
and deltoken
will point to that empty string.
If you choose to use strtok()
then:
char* token = strtok( line, " " ) ;
if( strcmp( token, "DEL" ) == 0 )
{
char* itemDeleting = strtok( NULL, " " ) ;
remove(itemDeleting);
send(client, "
" ,strlen("
"),0);
}
However if is simpler to avoid the complexity of strtok()
, and the fact that it modifies line
by inserting nuls makes it undesirable in many cases. The code above also won't work if a filename may contains spaces.
There are many alternative solutions, for example:
size_t delimiter_index = strcspn( line, " " ) ;
if( strncmp( line, "DEL", delimiter_index ) == 0 )
{
char* itemDeleting = &line[delimiter_index] ;
while( *itemDeleting == 0 && *itemDeleting != '' ) itemDeleting++ ;
remove(itemDeleting);
send(client, "
" ,strlen("
"),0);
}
Since I have no idea what StartsWithDEL()
or trim()
so I have avoided them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…