#include #include rtrim(char* str) { char* spot = NULL; while (str && *str) { if (isspace(*str)) { if (!spot) { spot = str; } } else { spot = NULL; } str++; } if (spot) { *spot = 0; } } void testit(const char* lit) { printf("=====================================================\n"); char buf[256]; strcpy(buf, lit); printf("len: %d buf: .%s.\n", strlen(buf), buf); rtrim(buf); printf("len: %d buf: .%s.\n", strlen(buf), buf); printf("=====================================================\n"); printf("=====================================================\n"); } int main(int argc, char** argv) { testit("Hello World "); testit(" Hello World "); testit("Hello World\t\t\t\n\n\n"); testit("Hello"); testit(""); testit(" "); return 0; }