Go to the documentation of this file.00001
00017 #include <string.h>
00018 #include <grass/gis.h>
00019
00020
00038 int G_insert_commas(char *buf)
00039 {
00040 char number[100];
00041 int i, len;
00042 int comma;
00043
00044 while (*buf == ' ')
00045 buf++;
00046 strcpy(number, buf);
00047 for (len = 0; number[len]; len++)
00048 if (number[len] == '.')
00049 break;
00050 if (len < 5)
00051 return 1;
00052
00053 i = 0;
00054 if ((comma = len % 3)) {
00055 while (i < comma)
00056 *buf++ = number[i++];
00057 *buf++ = ',';
00058 }
00059
00060 for (comma = 0; number[i]; comma++) {
00061 if (number[i] == '.')
00062 break;
00063 if (comma && (comma % 3 == 0))
00064 *buf++ = ',';
00065 *buf++ = number[i++];
00066 }
00067 while (number[i])
00068 *buf++ = number[i++];
00069 *buf = 0;
00070
00071 return 0;
00072 }
00073
00074
00088 int G_remove_commas(char *buf)
00089 {
00090 char *b;
00091
00092 for (b = buf; *b; b++)
00093 if (*b != ',')
00094 *buf++ = *b;
00095
00096 *buf = 0;
00097
00098 return 0;
00099 }