diff options
Diffstat (limited to 'string_utils.c')
-rw-r--r-- | string_utils.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/string_utils.c b/string_utils.c index 5763e27..68091e5 100644 --- a/string_utils.c +++ b/string_utils.c @@ -38,7 +38,7 @@ gboolean String_is_it_numeric(char *parameter) void String_Parameter_To_Text(float Float_To_Convert, int significant_digits, - char *start_string,char *units,char *LCD_string,int show_plus_sign) + char *start_string,char *units,gchar **LCD_string,int show_plus_sign) { gchar *floating_val = NULL; gchar *unit_mult = NULL; /* units multiplier, eg. M, k, u */ @@ -47,23 +47,18 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits, /* is annoying. (e.g. 1.000 -> 0.999) */ /* Move the decimal with string manipulations instead. */ - strcpy(LCD_string,start_string); + GString *out_gstr = g_string_new (start_string); /* if significant_digits is zero, used the supplied integer rather than the floating number */ if (!significant_digits) { - gchar *out_val; - out_val = g_strdup_printf ("%d", (int) Float_To_Convert); - strcat(LCD_string,out_val); - g_free (out_val); + g_string_append_printf (out_gstr, "%d", (int) Float_To_Convert); } else { int i; int shift_decimal_by; /* if the exponent isn't a multiple of 3, the decimal point will be moved */ int decimal_location; /* where the decimal is in the number string */ int exponent_val; /* the exponent, in integer form */ - GString *out_gstr = g_string_new (""); - Float_To_Text(remote_digits_after_decimal,Float_To_Convert,&floating_val); /* -- COPY FIRST ONE OR TWO CHARACTERS -- */ @@ -132,19 +127,21 @@ void String_Parameter_To_Text(float Float_To_Convert, int significant_digits, /* -- FINISH UP -- */ - strcat(LCD_string,out_gstr->str); - g_string_free (out_gstr, TRUE); - + /* -- CHECK FOR TERMINATING DECIMAL POINT -- */ - if (LCD_string[strlen(LCD_string)-1]=='.') { - LCD_string[strlen(LCD_string)-1]=0; + int len = strlen(out_gstr->str); + if (LCD_string[len-1]=='.') { + out_gstr = g_string_erase (out_gstr, len-1, 1); } - strcat(LCD_string,unit_mult); + out_gstr = g_string_append (out_gstr, unit_mult); } - strcat(LCD_string,units); + out_gstr = g_string_append (out_gstr, units); + + *LCD_string = g_strdup (out_gstr->str); + g_string_free (out_gstr, TRUE); g_free (floating_val); g_free (unit_mult); } |