- 论坛徽章:
- 0
|
俺胡老师给俺一段代码,据说能看出你的函数的BUG,你先试试
- /*
- * Remove any tabs and spaces from the begining and the end of
- * a string
- */
- char* trim(char* _s)
- {
- int len;
- char* end;
- /* Null pointer, there is nothing to do */
- if (!_s) return _s;
- /* Remove spaces and tabs from the begining of string */
- while ((*_s == ' ') || (*_s == '\t')) _s++;
- len = strlen(_s);
- end = _s + len - 1;
- /* Remove trailing spaces and tabs */
- while ((*end == ' ') || (*end == '\t')) end--;
- if (end != (_s + len - 1)) {
- *(end+1) = '\0';
- }
- return _s;
- }
- struct foxbase
- {
- char a[4];
- char b[4];
- };
- int main( int argc, char* argv[] )
- {
- struct foxbase t;
- bzero( &t, sizeof( t ) );
- strcpy( t.a, "\t\t\t\t" );
- cout << "(" << t.a << ")" << endl;
- trim( t.b );
- cout << "(" << t.a << ")" << endl;
- return 0;
- }
复制代码 |
|