公告版位

沒有痛苦 就沒有收穫
若內容對你有幫助,可以留言讓我知道哦~
有問題想要諮詢可以請至這裡連絡我哦 =>不會就放這邊

 


目前分類:C (41)

瀏覽方式: 標題列表 簡短摘要

https://www.onlinegdb.com/online_c++_debugger

 

#include <iostream>

JL8051 發表在 痞客邦 留言(0) 人氣()

這大陸文章先備份,怕哪天就沒了

設定某個bit為0或1的程式

用C寫的,還蠻清楚的,就給各位參考囉

JL8051 發表在 痞客邦 留言(0) 人氣()

#include <stdio.h>
union{
    int myint;
    struct {
        char char4;
        char char3;
        char char2;
        char char1;
    } myChars;
}myUnion;


union{
    char mychar;
    struct {
        unsigned  bit0 :1;
        unsigned  bit1 :1;
        unsigned  bit2 :1;
        unsigned  bit3 :1;
        unsigned  bit4 :1;
        unsigned  bit5 :1;
        unsigned  bit6 :1;
        unsigned  bit7 :1;
    }bits;
}cc;



int main()
{
    myUnion.myint = 0x11223344;
    printf("1=%x\n", myUnion.myChars.char1);
    printf("2=%x\n", myUnion.myChars.char2);
    printf("3=%x\n", myUnion.myChars.char3);
    printf("4=%x\n", myUnion.myChars.char4);
    //yourUnion.yourSplitInterger = 0x1234;
    
    cc.bits.bit0 = 1;
    return 0;
}

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

0xFul,

0X代表十六進制,

F是十六進制的15,

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

Turbo C/C++ 以產生10個介於0~99之間的亂數為例
#include<stdio.h>
#include<stdlib.h>
int main(){
        int a,times=0;
        randomize();
        while(times<=10){
                a=random(100);
                printf("%d\n",a);
                times++;
        }
puts("\n");
return 0;
}

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

最近發現C有個寫法很怪

明明

int *a;
文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

Q1:預處理器 (Preprocessor),用預處理指令 #define 宣告一個常數,用以表示 1 年中有多少秒 (忽略閏年問題)。


ANS:#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL

文章標籤

JL8051 發表在 痞客邦 留言(2) 人氣()

今天要說明的是,在C語言中,2個byte如果要轉十進制 如何做?

2個byte分別為high byte 和 low byte,可以組合成一個0-65535大小的十進制 ,

在C語言可以這樣寫:

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

printf之變數參數

轉 換 字 元

以何種形式列印對應的引數

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

C範例 - 輸入判斷程式碼
printf("開始燒錄? 輸入 Y or N :\n");
        char c;
        scanf("%c", &c);
        while (c == 'Y' || c =='N' || c =='y' || c== 'n'){
            if (c == 'Y' || c =='y')
            break;
            else
            exit(1);
        }

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

        do
        { 
                //一直做放這邊的程式 直到你按下q
        }while(ch!='q');

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

步驟1

先下載 RS232 for Windows Librery → http://www.teuniz.net/RS-232/

將 RS-232.tar.gz 解壓縮,只需要 rs232.c 和 rs232.h 即可。

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

C語法 - printf 兩個位元補0

printf("%02x\n", buffer[i]);  //兩個位元補0

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

C語言紀錄程式執行時間的方法
最近一直在比程式的執行速度,測的方法又五花八門@@
這邊就記一個用time.h中的函式來計算所花時間的辦法:

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

C語言浮點數相加語法

printf("Temperature Channel %d = %6.2f ℃\n", index, (float)((temperature >>6) & 0x1ff) + (((float)(temperature & 0x3f)) * 0.015625));

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

型態 uint8_t, uint16_t, uint32_t, uint64_t分別可以對照成
型態 usigned char, unsigned short, unsigned int, unsigned long long

那麼他們各自的範圍又是如何呢?

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

C範例- SCANF兩個輸入
      while(1) {
                listitem();
                scanf ("%d",&cmd);    //第一個輸入
                scanf ("%x",&str);   //x 十六進制 第二個輸入

                printf("QQQQQQ= 0x%x\n", str);
                switch (cmd) {
                case 1:
                        pwm.frequency = F1;
                        pwm.type = MT;
                        pwm.ctrl_pin = P0;
                        pwm.duty_cycle = str;
                        ioctl(fd, PWM_SET, &pwm);
                        break;

      }

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

0x10變0X80 C語言
char upset(char dat)  
{  //用 12345678 
     dat=(dat>>4)|(dat<<4); //dat 變成 56781234
     dat=((dat&0xcc)>>2)|((dat&0x33)<<2);//dat=78563412
     dat=((dat&0xaa)>>1)|((dat&0x55)<<1);//dat=87654321
     return dat;
 } 

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

最近在用scanf 發現 輸入完數值後enter

會有程式誤判的情況

最後我用這樣解掉

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

四個數字 從小排到大 由大排到小
#include <stdio.h>

 

int main(){

  

   int a,b,c,d;

   int temp=0;

   scanf("%d%d%d%d",&a,&b,&c,&d);

  

   if (a>b){

       temp =a;

       a=b;

       b=temp;

   }

   if (a>c){

       temp =a;

       a=c;

       c=temp;

   }

   if (a>d){

       temp =a;

       a=d;

       d=temp;

   }

 

   if (b>a){

       temp =b;

       b=a;

       a=temp;

   }

   if (b>c){

       temp =b;

       b=c;

       c=temp;

   }

   if (b>d){

       temp =b;

       b=d;

       d=temp;

   }

  

   if (c>a){

       temp =c;

       c=a;

       a=temp;

   }

   if (c>b){

       temp =c;

       c=b;

       b=temp;

   }

   if (c>d){

       temp =c;

       c=d;

       d=temp;

   }

  

   if (d>a){

       temp =d;

       d=a;

       a=temp;

   }

   if (d>b){

       temp =d;

       d=b;

       b=temp;

   }

   if (d>c){

       temp =d;

       d=c;

       c=temp;

   }

   printf("%d%d%d%d\n",a,b,c,d);

 

 

 

   if (a<b){

       temp =a;

       a=b;

       b=temp;

   }

   if (a<c){

       temp =a;

       a=c;

       c=temp;

   }

   if (a<d){

       temp =a;

       a=d;

       d=temp;

   }

 

   if (b<a){

       temp =b;

       b=a;

       a=temp;

   }

   if (b<c){

       temp =b;

       b=c;

       c=temp;

   }

   if (b<d){

       temp =b;

       b=d;

       d=temp;

   }

  

   if (c<a){

       temp =c;

       c=a;

       a=temp;

   }

   if (c<b){

       temp =c;

       c=b;

       b=temp;

   }

   if (c<d){

       temp =c;

       c=d;

       d=temp;

   }

  

   if (d<a){

       temp =d;

       d=a;

       a=temp;

   }

   if (d<b){

       temp =d;

       d=b;

       b=temp;

   }

   if (d<c){

       temp =d;

       d=c;

       c=temp;

   }

   printf("%d%d%d%d",a,b,c,d);

}

文章標籤

JL8051 發表在 痞客邦 留言(0) 人氣()

1 23