How to trim a string in C

Trim a string

The problem of removing leading and trailing whitespace characters in strings occurs in programming quite often. Here is a solution.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

void trim (char *dest, char *src); 

int main (int argc, char **argv)
{
    char inbuf [1024];
    char outbuf [1024];

    printf ("Type a string : ");
    while (fgets (inbuf, 1024, stdin) !=
Read more