codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <stdio.h> #include <string.h> #include <ctype.h> void trim (char *cs) { char *p; size_t len = strlen(cs); for (p = cs + len - 1; isspace (*p); --p) /* nothing */ ; p[1] = '\0'; for (p = cs; isspace (*p); ++p) /* nothing */ ; memmove (cs, p, len - (size_t) (p - cs) + 1); } void test () { char input[1000]; printf ("Enter something: "); fgets (input, sizeof input, stdin); trim (input); printf ("|%s|\n", input); } int main() { test(); return 0; }
Private
[
?
]
Run code
Submit