[ create a new paste ] login | about

Link: http://codepad.org/FUeYvOEa    [ raw code | output | fork ]

C, pasted on Aug 28:
#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;
}


Output:
1
Enter something: ||


Create a new paste based on this one


Comments: