當前位置:首頁 » 編程語言 » 多項式0x1021C語言
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

多項式0x1021C語言

發布時間: 2022-04-02 12:09:11

1. 怎麼做Crc16校驗 CRC多項式0x1021-CSDN論壇

http://www.cnblogs.com/Msisiterc/archive/2011/12/20/2294910.html
用的是第二種方法

2. 如何用c語言實現一元多項式簡單計算器的設計

  1. 一元多項式簡單的計算器的功能:
    1)輸入並建立多項式;
    2)輸出多項式;
    3)兩個多項式相加,輸出和多項式;
    4)兩個多項式相減,輸出差多項式。

  2. 常式

    #include<dos.h>/*DOS介面函數*/
    #include<math.h>/*數學函數的定義*/
    #include<conio.h>/*屏幕操作函數*/
    #include<stdio.h>/*I/O函數*/
    #include<stdlib.h>/*庫函數*/
    #include<stdarg.h>/*變數長度參數表*/
    #include<graphics.h>/*圖形函數*/
    #include<string.h>/*字元串函數*/
    #include<ctype.h>/*字元操作函數*/
    #defineUP0x48/*游標上移鍵*/
    #defineDOWN0x50/*游標下移鍵*/
    #defineLEFT0x4b/*游標左移鍵*/
    #defineRIGHT0x4d/*游標右移鍵*/
    #defineENTER0x0d/*回車鍵*/
    void*rar;/*全局變數,保存游標圖象*/
    structpalettetypepalette;/*使用調色板信息*/
    intGraphDriver;/*圖形設備驅動*/
    intGraphMode;/*圖形模式值*/
    intErrorCode;/*錯誤代碼*/
    intMaxColors;/*可用顏色的最大數值*/
    intMaxX,MaxY;/*屏幕的最大解析度*/
    doubleAspectRatio;/*屏幕的像素比*/
    voiddrawboder(void);/*畫邊框函數*/
    voidinitialize(void);/*初始化函數*/
    voidcomputer(void);/*計算器計算函數*/
    voidchangetextstyle(intfont,intdirection,intcharsize);/*改變文本樣式函數*/
    voidmwindow(char*header);/*窗口函數*/
    intspecialkey(void);/*獲取特殊鍵函數*/
    intarrow();/*設置箭頭游標函數*/
    /*主函數*/
    intmain()
    {
    initialize();/*設置系統進入圖形模式*/
    computer();/*運行計算器*/
    closegraph();/*系統關閉圖形模式返迴文本模式*/
    return(0);/*結束程序*/
    }
    /*設置系統進入圖形模式*/
    voidinitialize(void)
    {
    intxasp,yasp;/*用於讀x和y方向縱橫比*/
    GraphDriver=DETECT;/*自動檢測顯示器*/
    initgraph(&GraphDriver,&GraphMode,"");
    /*初始化圖形系統*/
    ErrorCode=graphresult();/*讀初始化結果*/
    if(ErrorCode!=grOk)/*如果初始化時出現錯誤*/
    {
    printf("GraphicsSystemError:%s ",
    grapherrormsg(ErrorCode));/*顯示錯誤代碼*/
    exit(1);/*退出*/
    }
    getpalette(&palette);/*讀面板信息*/
    MaxColors=getmaxcolor()+1;/*讀取顏色的最大值*/
    MaxX=getmaxx();/*讀屏幕尺寸*/
    MaxY=getmaxy();/*讀屏幕尺寸*/
    getaspectratio(&xasp,&yasp);/*拷貝縱橫比到變數中*/
    AspectRatio=(double)xasp/(double)yasp;/*計算縱橫比值*/
    }
    /*計算器函數*/
    voidcomputer(void)
    {
    structviewporttypevp;/*定義視口類型變數*/
    intcolor,height,width;
    intx,y,x0,y0,i,j,v,m,n,act,flag=1;
    floatnum1=0,num2=0,result;/*操作數和計算結果變數*/
    charcnum[5],str2[20]={""},c,temp[20]={""};
    charstr1[]="1230.456+-789*/Qc=^%";/*定義字元串在按鈕圖形上顯示的符號*/
    mwindow("Calculator");/*顯示主窗口*/
    color=7;/*設置灰顏色值*/
    getviewsettings(&vp);/*讀取當前窗口的大小*/
    width=(vp.right+1)/10;/*設置按鈕寬度*/
    height=(vp.bottom-10)/10;/*設置按鈕高度*/
    x=width/2;/*設置x的坐標值*/
    y=height/2;/*設置y的坐標值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(x+width*2,y,x+7*width,y+height);
    /*畫一個二維矩形條顯示運算數和結果*/
    setcolor(color+3);/*設置淡綠顏色邊框線*/
    rectangle(x+width*2,y,x+7*width,y+height);
    /*畫一個矩形邊框線*/
    setcolor(RED);/*設置顏色為紅色*/
    outtextxy(x+3*width,y+height/2,"0.");/*輸出字元串"0."*/
    x=2*width-width/2;/*設置x的坐標值*/
    y=2*height+height/2;/*設置y的坐標值*/
    for(j=0;j<4;++j)/*畫按鈕*/
    {
    for(i=0;i<5;++i)
    {
    setfillstyle(SOLID_FILL,color);
    setcolor(RED);
    bar(x,y,x+width,y+height);/*畫一個矩形條*/
    rectangle(x,y,x+width,y+height);
    sprintf(str2,"%c",str1[j*5+i]);
    /*將字元保存到str2中*/
    outtextxy(x+(width/2),y+height/2,str2);
    x=x+width+(width/2);/*移動列坐標*/
    }
    y+=(height/2)*3;/*移動行坐標*/
    x=2*width-width/2;/*復位列坐標*/
    }
    x0=2*width;
    y0=3*height;
    x=x0;
    y=y0;
    gotoxy(x,y);/*移動游標到x,y位置*/
    arrow();/*顯示游標*/
    putimage(x,y,rar,XOR_PUT);
    m=0;
    n=0;
    strcpy(str2,"");/*設置str2為空串*/
    while((v=specialkey())!=45)/*當壓下Alt+x鍵結束程序,否則執行下面的循環*/
    {
    while((v=specialkey())!=ENTER)/*當壓下鍵不是回車時*/
    {
    putimage(x,y,rar,XOR_PUT);/*顯示游標圖象*/
    if(v==RIGHT)/*右移箭頭時新位置計算*/
    if(x>=x0+6*width)
    /*如果右移,移到尾,則移動到最左邊字元位置*/
    {
    x=x0;
    m=0;
    }
    else
    {
    x=x+width+width/2;
    m++;
    }/*否則,右移到下一個字元位置*/
    if(v==LEFT)/*左移箭頭時新位置計算*/
    if(x<=x0)
    {
    x=x0+6*width;
    m=4;
    }/*如果移到頭,再左移,則移動到最右邊字元位置*/
    else
    {
    x=x-width-width/2;
    m--;
    }/*否則,左移到前一個字元位置*/
    if(v==UP)/*上移箭頭時新位置計算*/
    if(y<=y0)
    {
    y=y0+4*height+height/2;
    n=3;
    }/*如果移到頭,再上移,則移動到最下邊字元位置*/
    else
    {
    y=y-height-height/2;
    n--;
    }/*否則,移到上邊一個字元位置*/
    if(v==DOWN)/*下移箭頭時新位置計算*/
    if(y>=7*height)
    {
    y=y0;
    n=0;
    }/*如果移到尾,再下移,則移動到最上邊字元位置*/
    else
    {
    y=y+height+height/2;
    n++;
    }/*否則,移到下邊一個字元位置*/
    putimage(x,y,rar,XOR_PUT);/*在新的位置顯示游標箭頭*/
    }
    c=str1[n*5+m];/*將字元保存到變數c中*/
    if(isdigit(c)||c=='.')/*判斷是否是數字或小數點*/
    {
    if(flag==-1)/*如果標志為-1,表明為負數*/
    {
    strcpy(str2,"-");/*將負號連接到字元串中*/
    flag=1;
    }/*將標志值恢復為1*/
    sprintf(temp,"%c",c);/*將字元保存到字元串變數temp中*/
    strcat(str2,temp);/*將temp中的字元串連接到str2中*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,str2);/*顯示字元串*/
    }
    if(c=='+')
    {
    num1=atof(str2);/*將第一個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=1;/*做計算加法標志值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='-')
    {
    if(strcmp(str2,"")==0)/*如果str2為空,說明是負號,而不是減號*/
    flag=-1;/*設置負數標志*/
    else
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=2;/*做計算減法標志值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*畫矩形*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    }
    if(c=='*')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=3;/*做計算乘法標志值*/
    setfillstyle(SOLID_FILL,color+3);bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='/')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=4;/*做計算除法標志值*/
    setfillstyle(SOLID_FILL,color+3);
    bar(2*width+width/2,height/2,15*width/2,3*height/2);
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='^')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=5;/*做計算乘方標志值*/
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*畫矩形*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='%')
    {
    num1=atof(str2);/*將第二個操作數轉換為浮點數*/
    strcpy(str2,"");/*將str2清空*/
    act=6;/*做計算模運算乘方標志值*/
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*畫矩形*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='=')
    {
    num2=atof(str2);/*將第二個操作數轉換為浮點數*/
    switch(act)/*根據運算符號計算*/
    {
    case1:result=num1+num2;break;/*做加法*/
    case2:result=num1-num2;break;/*做減法*/
    case3:result=num1*num2;break;/*做乘法*/
    case4:result=num1/num2;break;/*做除法*/
    case5:result=pow(num1,num2);break;/*做x的y次方*/
    case6:result=fmod(num1,num2);break;/*做模運算*/
    }
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*覆蓋結果區*/
    sprintf(temp,"%f",result);/*將結果保存到temp中*/
    outtextxy(5*width,height,temp);/*顯示結果*/
    }
    if(c=='c')
    {
    num1=0;/*將兩個操作數復位0,符號標志為1*/
    num2=0;
    flag=1;
    strcpy(str2,"");/*將str2清空*/
    setfillstyle(SOLID_FILL,color+3);/*設置用淡綠色實體填充*/
    bar(2*width+width/2,height/2,15*width/2,3*height/2);/*覆蓋結果區*/
    outtextxy(5*width,height,"0.");/*顯示字元串*/
    }
    if(c=='Q')exit(0);/*如果選擇了q回車,結束計算程序*/
    }
    putimage(x,y,rar,XOR_PUT);/*在退出之前消去游標箭頭*/
    return;/*返回*/
    }
    /*窗口函數*/
    voidmwindow(char*header)
    {
    intheight;
    cleardevice();/*清除圖形屏幕*/
    setcolor(MaxColors-1);/*設置當前顏色為白色*/
    setviewport(20,20,MaxX/2,MaxY/2,1);/*設置視口大小*/
    height=textheight("H");/*讀取基本文本大小*/
    settextstyle(DEFAULT_FONT,HORIZ_DIR,1);/*設置文本樣式*/
    settextjustify(CENTER_TEXT,TOP_TEXT);/*設置字元排列方式*/
    outtextxy(MaxX/4,2,header);/*輸出標題*/
    setviewport(20,20+height+4,MaxX/2+4,MaxY/2+20,1);/*設置視口大小*/
    drawboder();/*畫邊框*/
    }
    voiddrawboder(void)/*畫邊框*/
    {
    structviewporttypevp;/*定義視口類型變數*/
    setcolor(MaxColors-1);/*設置當前顏色為白色*/
    setlinestyle(SOLID_LINE,0,NORM_WIDTH);/*設置畫線方式*/
    getviewsettings(&vp);/*將當前視口信息裝入vp所指的結構中*/
    rectangle(0,0,vp.right-vp.left,vp.bottom-vp.top);/*畫矩形邊框*/
    }
    /*設計滑鼠圖形函數*/
    intarrow()
    {
    intsize;
    intraw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4};/*定義多邊形坐標*/
    setfillstyle(SOLID_FILL,2);/*設置填充模式*/
    fillpoly(8,raw);/*畫出一游標箭頭*/
    size=imagesize(4,4,16,16);/*測試圖象大小*/
    rar=malloc(size);/*分配內存區域*/
    getimage(4,4,16,16,rar);/*存放游標箭頭圖象*/
    putimage(4,4,rar,XOR_PUT);/*消去游標箭頭圖象*/
    return0;
    }
    /*按鍵函數*/
    intspecialkey(void)
    {
    intkey;
    while(bioskey(1)==0);/*等待鍵盤輸入*/
    key=bioskey(0);/*鍵盤輸入*/
    key=key&0xff?key&0xff:key>>8;/*只取特殊鍵的掃描值,其餘為0*/
    return(key);/*返回鍵值*/
    }

3. crc8校驗:多項式二(0x07)為什麼是X8 + X2 + X + 1

商城

論壇

活動

招聘

GitChat

ITeye

專題

打開CSDN APP

Copyright © 1999-2019, CSDN.NET, All Rights Reserved

登錄

原 java實現 CRC8 校驗 多項式 x8+x2+x+1

DunnX閱讀數:3922018-12-19

 

物聯網 伺服器需要檢驗設備傳輸的數據,設備c語言寫的,CRC8 校驗多項式為  x8+x2+x+1,找了網路,必應。也沒有找到java CRC8  多項式  x8+x2+x+1的實現,能找到的都是x8+x5+x4+1的,後轉google,費了些功夫不過還好找到了。不說了,上代碼。

package com.smartsocket.utils;

/**

*

*

* @author zs

*/

public class CRC8Util {

/**

* CRC8 校驗 多項式 x8+x2+x+1

* @param b

* @param off

* @param len

* @return

*/

public static byte CRC8Check(final byte[] b, final int off, final int len){

byte result=0x00;

for (int i = 0; i < len; i++) {

result = CHECKSUM_TABLE[(result ^ (b[i + of

(byte) 0x95, (byte) 0x92, (byte) 0x9b, (byte) 0x9c, (byte) 0xb1, (byte) 0xb6, (byte) 0xbf, (byte) 0xb8, (byte) 0xad,

(byte) 0xaa, (byte) 0xa3, (byte) 0xa4, (byte) 0xf9, (byte) 0xfe, (byte) 0xf7, (byte) 0xf0, (byte) 0xe5, (byte) 0xe2,

4. CRC的C語言的程序

按位計算CRC採用CRC-CCITT多項式,多項式為0x11021,C語言編程時,參與計算為0x1021。當按位計算CRC時,例如計算二進制序列為1001 1010 1010 1111時,將二進制序列數左移16位,即為1001 1010 1010 1111 (0000 0000 0000 0000),實際上該二進制序列可拆分為1000 0000 0000 0000 (0000 0000 0000 0000) + 000 0000 0000 0000 (0000 0000 0000 0000) + 00 0000 0000 0000 (0000 0000 0000 0000) + 1 0000 0000 0000 (0000 0000 0000 0000) + ……
現在開始分析運算:
<1>對第一個二進制分序列求余數,豎式除法即為0x10000 ^ 0x11021運算,後面的0位保留;
<2>接著對第二個二進制分序列求余數,將第一步運算的余數*2後再和第二個二進制分序列一起對0x11021求余,這一步理解應該沒什麼問題。如果該分序列為0,無需計算。
<3>對其餘的二進制序列求余與上面兩步相同。
<4>計算到最後一位時即為整個二進制序列的余數,即為CRC校驗碼。
該計算方法相當於對每一位計算,運算過程很容易理解,所佔內存少,缺點是一位一位計算比較耗時。
下面給出C語言實現方法:
代碼如下:
unsigned char test[16] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff};
unsigned char len = 16;
void main( void )
{
unsigned long temp = 0;
unsigned int crc;
unsigned char i;
unsigned char *ptr = test;

while( len-- ) {
for(i = 0x80; i != 0; i = i >> 1) {
temp = temp * 2;
if((temp & 0x10000) != 0)
temp = temp ^ 0x11021;

if((*ptr & i) != 0)
temp = temp ^ (0x10000 ^ 0x11021);
}
ptr++;
}
crc = temp;
printf("0x%x ",crc);
}

5. C語言編程(要發送的數據為101110,採用CRC的生成多項式是P(X)=Xe3+1,試求應添加在數據後面的余數),

發送的數是:0x2E
這個e要精確的么?

6. C語言函數問題

分類函數,所在函數庫為ctype.h
int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否則返回0
int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或數字('0'-'9')
返回非0值,否則返回0
int isascii(int ch) 若ch是字元(ASCII碼中的0-127)返回非0值,否則返回0
int iscntrl(int ch) 若ch是作廢字元(0x7F)或普通控制字元(0x00-0x1F)
返回非0值,否則返回0
int isdigit(int ch) 若ch是數字('0'-'9')返回非0值,否則返回0
int isgraph(int ch) 若ch是可列印字元(不含空格)(0x21-0x7E)返回非0值,否則返回0
int islower(int ch) 若ch是小寫字母('a'-'z')返回非0值,否則返回0
int isprint(int ch) 若ch是可列印字元(含空格)(0x20-0x7E)返回非0值,否則返回0
int ispunct(int ch) 若ch是標點字元(0x00-0x1F)返回非0值,否則返回0
int isspace(int ch) 若ch是空格(' '),水平製表符('\t'),回車符('\r'),
走紙換行('\f'),垂直製表符('\v'),換行符('\n')
返回非0值,否則返回0
int isupper(int ch) 若ch是大寫字母('A'-'Z')返回非0值,否則返回0
int isxdigit(int ch) 若ch是16進制數('0'-'9','A'-'F','a'-'f')返回非0值,
否則返回0
int tolower(int ch) 若ch是大寫字母('A'-'Z')返回相應的小寫字母('a'-'z')
int toupper(int ch) 若ch是小寫字母('a'-'z')返回相應的大寫字母('A'-'Z')

數學函數,所在函數庫為math.h、stdlib.h、string.h、float.h
int abs(int i) 返回整型參數i的絕對值
double cabs(struct complex znum) 返回復數znum的絕對值
double fabs(double x) 返回雙精度參數x的絕對值
long labs(long n) 返回長整型參數n的絕對值
double exp(double x) 返回指數函數ex的值
double frexp(double value,int *eptr) 返回value=x*2n中x的值,n存貯在eptr中
double ldexp(double value,int exp); 返回value*2exp的值
double log(double x) 返回logex的值
double log10(double x) 返回log10x的值
double pow(double x,double y) 返回xy的值
double pow10(int p) 返回10p的值
double sqrt(double x) 返回+√x的值
double acos(double x) 返回x的反餘弦cos-1(x)值,x為弧度
double asin(double x) 返回x的反正弦sin-1(x)值,x為弧度
double atan(double x) 返回x的反正切tan-1(x)值,x為弧度
double atan2(double y,double x) 返回y/x的反正切tan-1(x)值,y的x為弧度
double cos(double x) 返回x的餘弦cos(x)值,x為弧度
double sin(double x) 返回x的正弦sin(x)值,x為弧度
double tan(double x) 返回x的正切tan(x)值,x為弧度
double cosh(double x) 返回x的雙曲餘弦cosh(x)值,x為弧度
double sinh(double x) 返回x的雙曲正弦sinh(x)值,x為弧度
double tanh(double x) 返回x的雙曲正切tanh(x)值,x為弧度
double hypot(double x,double y) 返回直角三角形斜邊的長度(z),
x和y為直角邊的長度,z2=x2+y2
double ceil(double x) 返回不小於x的最小整數
double floor(double x) 返回不大於x的最大整數
void srand(unsigned seed) 初始化隨機數發生器
int rand() 產生一個隨機數並返回這個數
double poly(double x,int n,double c[])從參數產生一個多項式
double modf(double value,double *iptr)將雙精度數value分解成尾數和階
double fmod(double x,double y) 返回x/y的余數
double frexp(double value,int *eptr) 將雙精度數value分成尾數和階
double atof(char *nptr) 將字元串nptr轉換成浮點數並返回這個浮點數
double atoi(char *nptr) 將字元串nptr轉換成整數並返回這個整數
double atol(char *nptr) 將字元串nptr轉換成長整數並返回這個整數
char *ecvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *fcvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *gcvt(double value,int ndigit,char *buf)
將數value轉換成字元串並存於buf中,並返回buf的指針
char *ultoa(unsigned long value,char *string,int radix)
將無符號整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *ltoa(long value,char *string,int radix)
將長整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *itoa(int value,char *string,int radix)
將整數value轉換成字元串存入string,radix為轉換時所用基數
double atof(char *nptr) 將字元串nptr轉換成雙精度數,並返回這個數,錯誤返回0
int atoi(char *nptr) 將字元串nptr轉換成整型數, 並返回這個數,錯誤返回0
long atol(char *nptr) 將字元串nptr轉換成長整型數,並返回這個數,錯誤返回0
double strtod(char *str,char **endptr)將字元串str轉換成雙精度數,並返回這個數,
long strtol(char *str,char **endptr,int base)將字元串str轉換成長整型數,
並返回這個數,
int matherr(struct exception *e)
用戶修改數學錯誤返回信息函數(沒有必要使用)
double _matherr(_mexcep why,char *fun,double *arg1p,
double *arg2p,double retval)
用戶修改數學錯誤返回信息函數(沒有必要使用)
unsigned int _clear87() 清除浮點狀態字並返回原來的浮點狀態
void _fpreset() 重新初使化浮點數學程序包
unsigned int _status87() 返回浮點狀態字
int chdir(char *path) 使指定的目錄path(如:"C:\\WPS")變成當前的工作目錄,成
功返回0
int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功
返回0
pathname為指定的目錄名和文件名,如"C:\\WPS\\TXT"
ffblk為指定的保存文件信息的一個結構,定義如下:
┏━━━━━━━━━━━━━━━━━━━━┓
┃struct ffblk ┃
┃{ ┃
┃ char ff_reserved[21]; /*DOS保留字*/ ┃
┃ char ff_attrib; /*文件屬性*/ ┃
┃ int ff_ftime; /*文件時間*/ ┃
┃ int ff_fdate; /*文件日期*/ ┃
┃ long ff_fsize; /*文件長度*/ ┃
┃ char ff_name[13]; /*文件名*/ ┃
┃} ┃
┗━━━━━━━━━━━━━━━━━━━━━┛
attrib為文件屬性,由以下字元代表
┏━━━━━━━━━┳━━━━━━━━━┓
┃FA_RDONLY 只讀文件┃FA_LABEL 卷標號 ┃
┃FA_HIDDEN 隱藏文件┃FA_DIREC 目錄 ┃
┃FA_SYSTEM 系統文件┃FA_ARCH 檔案 ┃
┗━━━━━━━━━┻━━━━━━━━━┛
例:
struct ffblk ff;
findfirst("*.wps",&ff,FA_RDONLY);

int findnext(struct ffblk *ffblk) 取匹配finddirst的文件,成功返回0
void fumerge(char *path,char *drive,char *dir,char *name,char *ext)
此函數通過盤符drive(C:、A:等),路徑dir(\TC、\BC\LIB等),
文件名name(TC、WPS等),擴展名ext(.EXE、.COM等)組成一個文件名
存與path中.
int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)
此函數將文件名path分解成盤符drive(C:、A:等),路徑dir(\TC、\BC\LIB等),
文件名name(TC、WPS等),擴展名ext(.EXE、.COM等),並分別存入相應的變數中.
int getcurdir(int drive,char *direc) 此函數返回指定驅動器的當前工作目錄名稱
drive 指定的驅動器(0=當前,1=A,2=B,3=C等)
direc 保存指定驅動器當前工作路徑的變數 成功返回0
char *getcwd(char *buf,iint n) 此函數取當前工作目錄並存入buf中,直到n個字
節長為為止.錯誤返回NULL
int getdisk() 取當前正在使用的驅動器,返回一個整數(0=A,1=B,2=C等)
int setdisk(int drive) 設置要使用的驅動器drive(0=A,1=B,2=C等),
返回可使用驅動器總數
int mkdir(char *pathname) 建立一個新的目錄pathname,成功返回0
int rmdir(char *pathname) 刪除一個目錄pathname,成功返回0
char *mktemp(char *template) 構造一個當前目錄上沒有的文件名並存於template中
char *searchpath(char *pathname) 利用MSDOS找出文件filename所在路徑,
,此函數使用DOS的PATH變數,未找到文件返回NULL

進程函數,所在函數庫為stdlib.h、process.h
void abort() 此函數通過調用具有出口代碼3的_exit寫一個終止信息於stderr,
並異常終止程序。無返回值
int exec…裝入和運行其它程序
int execl( char *pathname,char *arg0,char *arg1,…,char *argn,NULL)
int execle( char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[])
int execlp( char *pathname,char *arg0,char *arg1,…,NULL)
int execlpe(char *pathname,char *arg0,char *arg1,…,NULL,char *envp[])
int execv( char *pathname,char *argv[])
int execve( char *pathname,char *argv[],char *envp[])
int execvp( char *pathname,char *argv[])
int execvpe(char *pathname,char *argv[],char *envp[])
exec函數族裝入並運行程序pathname,並將參數
arg0(arg1,arg2,argv[],envp[])傳遞給子程序,出錯返回-1
在exec函數族中,後綴l、v、p、e添加到exec後,
所指定的函數將具有某種操作能力
有後綴 p時,函數可以利用DOS的PATH變數查找子程序文件。
l時,函數中被傳遞的參數個數固定。
v時,函數中被傳遞的參數個數不固定。
e時,函數傳遞指定參數envp,允許改變子進程的環境,
無後綴e時,子進程使用當前程序的環境。

void _exit(int status)終止當前程序,但不清理現場
void exit(int status) 終止當前程序,關閉所有文件,寫緩沖區的輸出(等待輸出),
並調用任何寄存器的"出口函數",無返回值

int spawn…運行子程序
int spawnl( int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL)
int spawnle( int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[])
int spawnlp( int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL)
int spawnlpe(int mode,char *pathname,char *arg0,char *arg1,…,
char *argn,NULL,char *envp[])
int spawnv( int mode,char *pathname,char *argv[])
int spawnve( int mode,char *pathname,char *argv[],char *envp[])
int spawnvp( int mode,char *pathname,char *argv[])
int spawnvpe(int mode,char *pathname,char *argv[],char *envp[])
spawn函數族在mode模式下運行子程序pathname,並將參數
arg0(arg1,arg2,argv[],envp[])傳遞給子程序.出錯返回-1
mode為運行模式
mode為 P_WAIT 表示在子程序運行完後返回本程序
P_NOWAIT 表示在子程序運行時同時運行本程序(不可用)
P_OVERLAY表示在本程序退出後運行子程序
在spawn函數族中,後綴l、v、p、e添加到spawn後,
所指定的函數將具有某種操作能力
有後綴 p時, 函數利用DOS的PATH查找子程序文件
l時, 函數傳遞的參數個數固定.
v時, 函數傳遞的參數個數不固定.
e時, 指定參數envp可以傳遞給子程序,允許改變子程序運行環境.
當無後綴e時,子程序使用本程序的環境.

int system(char *command) 將MSDOS命令command傳遞給DOS執行
轉換子程序,函數庫為math.h、stdlib.h、ctype.h、float.h
char *ecvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *fcvt(double value,int ndigit,int *decpt,int *sign)
將浮點數value轉換成字元串並返回該字元串
char *gcvt(double value,int ndigit,char *buf)
將數value轉換成字元串並存於buf中,並返回buf的指針
char *ultoa(unsigned long value,char *string,int radix)
將無符號整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *ltoa(long value,char *string,int radix)
將長整型數value轉換成字元串並返回該字元串,radix為轉換時所用基數
char *itoa(int value,char *string,int radix)
將整數value轉換成字元串存入string,radix為轉換時所用基數
double atof(char *nptr) 將字元串nptr轉換成雙精度數,並返回這個數,錯誤返回0
int atoi(char *nptr) 將字元串nptr轉換成整型數, 並返回這個數,錯誤返回0
long atol(char *nptr) 將字元串nptr轉換成長整型數,並返回這個數,錯誤返回0
double strtod(char *str,char **endptr)將字元串str轉換成雙精度數,並返回這個數,
long strtol(char *str,char **endptr,int base)將字元串str轉換成長整型數,
並返回這個數,
int toascii(int c) 返回c相應的ASCII
int tolower(int ch) 若ch是大寫字母('A'-'Z')返回相應的小寫字母('a'-'z')
int _tolower(int ch) 返回ch相應的小寫字母('a'-'z')
int toupper(int ch) 若ch是小寫字母('a'-'z')返回相應的大寫字母('A'-'Z')
int _toupper(int ch) 返回ch相應的大寫字母('A'-'Z')

診斷函數,所在函數庫為assert.h、math.h
void assert(int test) 一個擴展成if語句那樣的宏,如果test測試失敗,
就顯示一個信息並異常終止程序,無返回值
void perror(char *string) 本函數將顯示最近一次的錯誤信息,格式如下:
字元串string:錯誤信息
char *strerror(char *str) 本函數返回最近一次的錯誤信息,格式如下:
字元串str:錯誤信息
int matherr(struct exception *e)
用戶修改數學錯誤返回信息函數(沒有必要使用)
double _matherr(_mexcep why,char *fun,double *arg1p,
double *arg2p,double retval)
用戶修改數學錯誤返回信息函數(沒有必要使用)

7. c語言問題。。。

#include<stdio.h>
void main()
{
int f(int [] ,int );
int x,i,c;
int a[8];
printf("please putin x:\n");
scanf("%d",&x);
printf("please putin arry:\n");
for(i=0; i<8; i++)
scanf("%d",&a[i]);
c=f(a,x);
printf("p(x)=%d",c);
}
int f(int a[],int b)
{
int x,g=a[0]*b,i;
for(i=1; i<8; i++)
g+=a[i]*b;
return(g);
}
程序裡面亂亂的東西太多了。你f中傳進去的參數完全沒有用,怎麼可能對呀,兄弟,呵呵
你好像我頭幾次寫程序的樣子呢。
第二題:
#include<stdio.h>
void main()
{
int x,i;
int a[8],sum=0;
printf("please putin x:\n");
scanf("%d",&x);
printf("please putin arry\n");
for(i=0; i<8; i++)
scanf("%d",&a[i]);
for(i=0; i<8; i++)
sum+=a[i]*x;
printf("p(x)=%d",sum);
printf("\n");
}
區別自己去找噢,這樣才能提高

8. C語言,多項式相乘

#include<stdio.h>
#include<stdlib.h>

typedefstructnode{
intcoefficient,power;
structnode*next;
}term;

term*new_term(intcoefficient,intpower){
term*t=(term*)malloc(sizeof(term));
t->next=NULL;
t->coefficient=coefficient;
t->power=power;
returnt;
}

voidfree_term(term*t){
free(t);
}

typedefstructlist{
termhead;
}polynomial;

voidinit_polynomial(polynomial*p){
p->head.next=NULL;
}

voidclear_polynomial(polynomial*p){
term*t=p->head.next;
term*del;
while(t!=NULL){
del=t;
t=t->next;
free_term(del);
}
p->head.next=NULL;
}

voidinsert_polynomial(polynomial*p,term*t){
t->next=p->head.next;
p->head.next=t;
}

voidsort(polynomial*p){
term*t;
term*next;
intfinish=0,temp;
while(!finish){
finish=1;
t=p->head.next;
while(t!=NULL){
next=t->next;
if(next!=NULL){
if(t->power<next->power){
temp=t->coefficient;
t->coefficient=next->coefficient;
next->coefficient=temp;
temp=t->power;
t->power=next->power;
next->power=temp;
finish=0;
}
}
t=next;
}
}
}

voidcombine(polynomial*p){
term*t=p->head.next;
term*next;
while(t!=NULL){
next=t->next;
if(next!=NULL&&next->power==t->power){
t->coefficient+=next->coefficient;
t->next=next->next;
free_term(next);
}
else{
t=next;
}
}
}

voidmultiply(polynomial*p1,polynomial*p2,polynomial*p3){
term*t1=p1->head.next;
term*t2;
clear_polynomial(p3);
init_polynomial(p3);
while(t1!=NULL){
t2=p2->head.next;
while(t2!=NULL){
insert_polynomial(p3,new_term(t1->coefficient*t2->coefficient,t1->power+t2->power));
t2=t2->next;
}
t1=t1->next;
}
sort(p3);
combine(p3);
}

voidinput(polynomial*p){
intcoef,power;
charc;
init_polynomial(p);
while(true){
scanf("%d%d",&coef,&power);
insert_polynomial(p,new_term(coef,power));
c=getchar();
if(c==' ')break;
}
sort(p);
combine(p);
}

voidoutput(polynomial*p){
term*t=p->head.next;
while(t!=NULL){
printf("%d%d",t->coefficient,t->power);
t=t->next;
}
}

intmain(){
inti;
polynomialp[3];
for(i=0;i<3;i++){
init_polynomial(&p[i]);
}
for(i=0;i<2;i++){
input(&p[i]);
}
multiply(&p[0],&p[1],&p[2]);
output(&p[2]);
}

9. C語言中CRC循環校驗的一個程序

while(len--!=0)
這句的len的值循環一次就減少1,先執行len!=0,再執行len--。
當len為0時退出循環。
for(i=0x80;
i!=0;
i/=2)
0x80是十六進制數,也即128
當i!=0時,執行循環體,
然後i=i/2,即i值減半。