GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
commas.c
Go to the documentation of this file.
1 
17 #include <string.h>
18 #include <grass/gis.h>
19 
20 
38 int G_insert_commas(char *buf)
39 {
40  char number[100];
41  int i, len;
42  int comma;
43 
44  while (*buf == ' ')
45  buf++;
46  strcpy(number, buf);
47  for (len = 0; number[len]; len++)
48  if (number[len] == '.')
49  break;
50  if (len < 5)
51  return 1;
52 
53  i = 0;
54  if ((comma = len % 3)) {
55  while (i < comma)
56  *buf++ = number[i++];
57  *buf++ = ',';
58  }
59 
60  for (comma = 0; number[i]; comma++) {
61  if (number[i] == '.')
62  break;
63  if (comma && (comma % 3 == 0))
64  *buf++ = ',';
65  *buf++ = number[i++];
66  }
67  while (number[i])
68  *buf++ = number[i++];
69  *buf = 0;
70 
71  return 0;
72 }
73 
74 
88 int G_remove_commas(char *buf)
89 {
90  char *b;
91 
92  for (b = buf; *b; b++)
93  if (*b != ',')
94  *buf++ = *b;
95 
96  *buf = 0;
97 
98  return 0;
99 }
float b
Definition: named_colr.c:8
int G_remove_commas(char *buf)
Removes commas from number string.
Definition: commas.c:88
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int G_insert_commas(char *buf)
Inserts commas into a number string.
Definition: commas.c:38