zoukankan      html  css  js  c++  java
  • STM32 (基础语法)笔记

    指针遍历:

    char *myitoa(int value, char *string, int radix)
    {
    int i, d;
    int flag = 0;
    char *ptr = string;

    /* This implementation only works for decimal numbers. */
    if (radix != 10)
    {
    *ptr = 0;
    return string;
    }

    if (!value)
    {
    *ptr++ = 0x30;
    *ptr = 0;
    return string;
    }

    /* if this is a negative value insert the minus sign. */
    if (value < 0)
    {
    *ptr++ = '-';

    /* Make the value positive. */
    value *= -1;
    }

    for (i = 10000; i > 0; i /= 10)
    {
    d = value / i;

    if (d || flag)
    {
    *ptr++ = (char)(d + 0x30);
    value -= (d * i);
    flag = 1;
    }
    }

    /* Null terminate the string. */
    *ptr = 0;
    return string;
    }


     
    void Str_To_ASC(char* a)  //±éÀú×Ö·û´®   Öð¸ö´¦Àí·ÖÎöתΪASCII¸ñʽ¸øNB
    {
        int i;
        int w;
        char val[10];
        char mess[20];
        for(i=0;a[i]!='';i++){
                if (a[i]=='.')
                {
                strcat(mess,"2e");  //替换“.”的ASCII码
                }    
                else if (a[i]=='-'){
          strcat(mess,"2d");  //替换“-”的ASCII码
     }else{ 
    w
    = a[i] - '0'+30; //µ¥¸ö×Ö·ûת
    int
    sprintf(val,"%d",w);
    strcat(mess,val);
    //Æ´½Ó×Ö·û
    }
    }
    strcpy(message,mess);
    // ×ªÒÆÎªÈ«¾Ö±äÁ¿
    printf("******%s******",message);
    }

    u8 是 unsigned char
    u16 是 unsigned short
    u32 是 unsigned int
    u8 * 就表示指向unsigned char(无符号字符类型)的指针,属于指针类型。


     (char*) p 是将p强行转换成指向char类型的指针。


    static 具有记忆功能和当时学esp8266的编程方式一样都用到了这个语法

  • 相关阅读:
    ADO.Net——增、删、改、查
    面向对象——类库五大原则
    面向对象——设计模式和委托
    JS 函数 内置方法和对象
    js 字符串、数组类型 及方法
    复习一下 Python三元运算
    复习一下 列表
    前端 2 CSS 选择器
    前端 1 HTML
    39
  • 原文地址:https://www.cnblogs.com/pengwenzheng/p/9733563.html
Copyright © 2011-2022 走看看