0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Mbedでitoa「整数を文字列」がない? (STM32L010)

Posted at

目的
少し容量に余裕が出てきた人むけ

参考

o_con378.jpg

Where is itoa() ?




#include "mbed.h"

//Serial pc(USBTX, USBRX); // tx, rx
//Serial pc(SERIAL_TX, SERIAL_RX); //767
RawSerial pc(PA_2, PA_3); //010

/*
** reverse string in place 
*/
void reverse(char *s) {
char *j;
int c;
 
  j = s + strlen(s) - 1;
  while(s < j) {
    c = *s;
    *s++ = *j;
    *j-- = c;
  }
}

/* itoa:  convert n to characters in s */
 void itoa(int n, char s[])
 {
     int i, sign;
 
     if ((sign = n) < 0)  /* record sign */
         n = -n;          /* make n positive */
     i = 0;
     do {       /* generate digits in reverse order */
         s[i++] = n % 10 + '0';   /* get next digit */
     } while ((n /= 10) > 0);     /* delete it */
     if (sign < 0)
         s[i++] = '-';
     s[i] = '\0';
     reverse(s);
 }


int main() {

    char ss1[16]; //文字列
    int ii; //ループカウンター

    //無限ループ
    while(1) {

        itoa(1234,ss1);
        ii=0; //ループカウンター
        while(ss1[ii]!=0){
            
            //一文字出力
            pc.putc(ss1[ii]);ii++;
                        
        } //while
        pc.putc('\r');
        pc.putc('\n');

        //1秒の待ち
        wait_ms(1000);
        
    } //while
} //main

//容量削減
void error(const char* format, ...){}




0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?