Florent Haddad / Mbed 2 deprecated DiscoLogger

Dependencies:   BSP_DISCO_L476VG COMPASS_DISCO_L476VG ConfigFile GYRO_DISCO_L476VG SDFileSystem mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers util.h Source File

util.h

00001 #ifndef UTIL
00002 #define UTIL
00003 #include "mbed.h"
00004 
00005 /*
00006 ** reverse string in place 
00007 */
00008 void reverse(char *s)  {
00009 char *j;
00010 int c;
00011  
00012   j = s + strlen(s) - 1;
00013   while(s < j) {
00014     c = *s;
00015     *s++ = *j;
00016     *j-- = c;
00017   }
00018 }
00019 
00020  void itoa(int n, char s[])
00021  {
00022      int i, sign;
00023  
00024      if ((sign = n) < 0)  /* record sign */
00025          n = -n;          /* make n positive */
00026      i = 0;
00027      do {       /* generate digits in reverse order */
00028          s[i++] = n % 10 + '0';   /* get next digit */
00029      } while ((n /= 10) > 0);     /* delete it */
00030      if (sign < 0)
00031          s[i++] = '-';
00032      s[i] = '\0';
00033      reverse(s);
00034  }
00035  #endif