Frans Korhonen / Mbed 2 deprecated RMCIOS-Mbed

Dependencies:   mbed mbed-rtos EthernetInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers string-conversion.c Source File

string-conversion.c

00001 #include "string-conversion.h"
00002 
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 
00006 /* String to float converter 
00007  * @param str String to convert from
00008  * returns the converted value. Returns 0 on failure. */
00009 int string_to_integer (const char *str)
00010 {
00011    return strtol (str, NULL, 0);
00012 }
00013 
00014 /* String to float converter 
00015  * @param str String to convert from
00016  * returns the converted value. Returns 0 on failure. */
00017 double string_to_float (const char *str)
00018 {
00019    return strtof (str, NULL);
00020 }
00021 
00022 /* Integer to string converter 
00023  * @param buffer buffer to write to
00024  * @param len size of buffer
00025  * @param value number to convert
00026  * @return number of characters the full string representation needs. */
00027 int integer_to_string (char *buffer, int len, int value)
00028 {
00029    return snprintf (buffer, len, "%d", value);
00030 }
00031 
00032 /* Float to string converter 
00033  * @param buffer buffer to write to
00034  * @param len size of buffer
00035  * @param value Number to convert
00036  * @return number of characters the full string representation needs.*/
00037 int float_to_string (char *buffer, int len, double value)
00038 {
00039    return snprintf (buffer, len, "%g", value);
00040 }
00041 
00042 
00043