Trim String
Trim String Documentation

Trim String - a simple string operation assignment

Introduction

A function trim() shall remove all leading and trailing whitespace characters. Whitespace characters are space (' ' ), tabulator ('\t'), new line ('
'), and line feed ('\r') charaters.

The function should be implemented in two variants: One variant copies a part of a string into another. The other variant manipulates the original string without creating a copy.

If we consider the string

"   This string can be trimmed  .     "

the trimmed version of it would be

"This string can be trimmed  ."

Assignment

  1. Implement the non-copying variant function trim() such that all unit tests pass.
  2. Implement the copying variant function trim_cpy() such that all unit tests pass.
  3. Avoid code duplication, functionality that is useful for each variant shall be implemented in private(!) functions.
  4. Avoid copying character by character (inefficient), use the appropriate strcpy function for this purpose.
  5. Implement the newly created main() function such that it accpets a string as command line argument and
    1. Stage 1: prints the command line arguments via printf().
    2. Stage 2: copies the command line arguments via strcpy() or sprintf() or character by character (a method you did not use when implementing trim()) into a newly declared character array of length 512.
    3. Stage 3: calls the function trim() and outputs the result into the stdout.
    4. A 'usage' line shall be printed to stdout if the number of actual command line arguments does not match the number of expected arguments.