File: CopyString.c

package info (click to toggle)
asclassic 1.1b-26
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,828 kB
  • ctags: 2,019
  • sloc: ansic: 21,403; makefile: 407; sh: 276
file content (38 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include "aftersteplib.h"
/***************************************************************************
 *
 * A simple routine to copy a string, stripping spaces and mallocing
 * space for the new string 
 ***************************************************************************/
void CopyString(char **dest, char *source)
{
  int len;
  char *start;
  
  while(((isspace((unsigned char)*source))&&(*source != '\n'))&&(*source != 0))
    {
      source++;
    }
  len = 0;
  start = source;
  while((*source != '\n')&&(*source != 0))
    {
      len++;
      source++;
    }
  
  source--;
  while((isspace((unsigned char)*source))&&(*source != 0)&&(len >0))
    {
      len--;
      source--;
    }
  *dest = safemalloc(len+1);
  strncpy(*dest,start,len);
  (*dest)[len]=0;	  
}