删除字符串右边的全部空格
来源:互联网 发布:多系统数据一直性 编辑:程序博客网 时间:2024/05/22 16:13
#include <iostream>using namespace std;//删除字符串右边的全部空格 char *my_trim( char *str ){ if (NULL == str) { throw; } char *const address = str; const int ONE_ELEMENT = 1; const char NULL_TERMINATED = '\0'; while (NULL_TERMINATED != *str) { ++str; } while (address != str && isspace( *(str - ONE_ELEMENT) )) { --str; } *str = NULL_TERMINATED; str = address; return str;}int main(int argc,char*argv[]){ char buf[] = "ok2002.com "; cout << strlen( buf ) << endl; my_trim( buf ); cout << strlen( buf ) << endl; system( "PAUSE" ); return EXIT_SUCCESS;}/*----2410请按任意键继续. . .-----------------------*/