SDDSlib
Loading...
Searching...
No Matches
trim_spaces.c File Reference

Implementation of trim_spaces function.. More...

#include "mdb.h"

Go to the source code of this file.

Functions

char * trim_spaces (char *s)
 Trims leading and trailing spaces from a string.
 

Detailed Description

Implementation of trim_spaces function..

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C Saunders, R. Soliday

Definition in file trim_spaces.c.

Function Documentation

◆ trim_spaces()

char * trim_spaces ( char * s)

Trims leading and trailing spaces from a string.

This function removes all leading and trailing space characters from the input string s by modifying it in place. It returns a pointer to the trimmed string.

Parameters
sThe string to be trimmed.
Returns
A pointer to the trimmed string.

Definition at line 28 of file trim_spaces.c.

28 {
29 char *ptr;
30 if (strlen(s) == 0)
31 return (s);
32 ptr = s;
33 while (*ptr == ' ')
34 ptr++;
35 if (ptr != s)
36 strcpy_ss(s, ptr);
37 ptr = s + strlen(s) - 1;
38 while (*ptr == ' ' && ptr != s)
39 ptr--;
40 *++ptr = 0;
41 return (s);
42}
char * strcpy_ss(char *dest, const char *src)
Safely copies a string, handling memory overlap.
Definition str_copy.c:34