C
Christopher Benson-Manica
(I want the purpose of the following code to be clear, and I'm sure
I've failed )
/* Assume that str is always of the form ([0-9]+[.])*[0-9]+ */
void DoStuff( const char *str )
{
const char *cp;
for ( cp=str ; cp ; cp=(cp=strchr(cp,'.'))?cp+1:0 ) {
/* do things with atoi(cp) */
}
}
Perhaps
void DoStuff( const char *str )
{
const char *cp;
cp=str;
while( cp ) {
if( cp == '.' )
cp++;
/* do things with atoi(cp) */
cp=strchr( cp, '.' );
}
}
would be better? Any even better suggestions?
I've failed )
/* Assume that str is always of the form ([0-9]+[.])*[0-9]+ */
void DoStuff( const char *str )
{
const char *cp;
for ( cp=str ; cp ; cp=(cp=strchr(cp,'.'))?cp+1:0 ) {
/* do things with atoi(cp) */
}
}
Perhaps
void DoStuff( const char *str )
{
const char *cp;
cp=str;
while( cp ) {
if( cp == '.' )
cp++;
/* do things with atoi(cp) */
cp=strchr( cp, '.' );
}
}
would be better? Any even better suggestions?