当前位置:首页 » 编程语言 » 多项式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值减半。