This may be common knowledge but I only came across it the other day.
The fact that sprintf, etc.. return the number of bytes can be fairly useful particularly in things like string parsing
to keep track of your position.
For example..
VOID MYCLASS::stringdecode (INT *b)
{ CHAR *iptr,*optr;
CHAR tmp[MAX_STRING_SIZE];
optr = tmp;
switch(*b)
{ default :iptr = lookup[foo].decodestr;
blah..blah..
}
blah...blah..
while (iptr != NULL)
{ if (*iptr++ == '%')
{ decode_y (iptr,&optr);
etc...
}
else
*optr++ = *iptr++;
}
}
VOID MYCLASS::decode_y (INT *data, CHAR **dst)
{ blah..blah..
if (test)
{ *dst += sprintf(*dst,"%s",mystring; }
else
{ *dst += sprintf(*dst,"$%02X,Y",*(data+1)); }
}
I have used this surprisingly often since a colleague pointed it out.
Hopefully it is not the first thing they teach in college these days or some such
The fact that sprintf, etc.. return the number of bytes can be fairly useful particularly in things like string parsing
to keep track of your position.
For example..
VOID MYCLASS::stringdecode (INT *b)
{ CHAR *iptr,*optr;
CHAR tmp[MAX_STRING_SIZE];
optr = tmp;
switch(*b)
{ default :iptr = lookup[foo].decodestr;
blah..blah..
}
blah...blah..
while (iptr != NULL)
{ if (*iptr++ == '%')
{ decode_y (iptr,&optr);
etc...
}
else
*optr++ = *iptr++;
}
}
VOID MYCLASS::decode_y (INT *data, CHAR **dst)
{ blah..blah..
if (test)
{ *dst += sprintf(*dst,"%s",mystring; }
else
{ *dst += sprintf(*dst,"$%02X,Y",*(data+1)); }
}
I have used this surprisingly often since a colleague pointed it out.
Hopefully it is not the first thing they teach in college these days or some such