C语言编写一个通讯录管理系统的源代码如下:
#include<stdioh>
#include<stringh>
#include<stdlibh>
/定义保存通迅录的信息/
structfriends
{
charname[20];/名字/
charprovince[20];/省份/
charcity[20];/所在城市/
charnation[20];/民族/
charsex[2];/性别M/F/
intage;/年龄/
}
扩展资料
1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。
2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。
3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。
这是我以前写的一个串口通讯文件,全部贴出来了,希望对你有帮助,包括设置,发送,接受数据,你可以好好看看,祝你成功
// 串口Dlgcpp : 实现文件
//
#include "stdafxh"
#include "串口h"
#include "串口Dlgh"
#include "afxdialogexh"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()
// C串口Dlg 对话框
C串口Dlg::C串口Dlg(CWnd pParent /=NULL/)
: CDialogEx(C串口Dlg::IDD, pParent)
, m_Selection(0)
, m_recv(_T(""))
, m_send(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void C串口Dlg::DoDataExchange(CDataExchange pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_MSCOMM1, m_CMscomm);
DDX_Control(pDX, IDC_COMBO2, m_CComboBox);
DDX_Text(pDX, IDC_RECV, m_recv);
DDX_Text(pDX, IDC_SEND, m_send);
}
BEGIN_MESSAGE_MAP(C串口Dlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &C串口Dlg::OnBnClickedButton1)
ON_CBN_SELCHANGE(IDC_COMBO2, &C串口Dlg::OnSelchangeCombo2)
ON_WM_LBUTTONDBLCLK()
ON_BN_CLICKED(IDC_BUTTON2, &C串口Dlg::OnBnClickedButton2)
ON_WM_DRAWITEM()
END_MESSAGE_MAP()
// C串口Dlg 消息处理程序
BOOL C串口Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// 将“关于”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenuLoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenuIsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此 *** 作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
// TODO: 在此添加额外的初始化代码
m_CMscommput_CommPort(2);
if(m_CMscommget_PortOpen())
m_CMscommput_PortOpen(0);//解除占用
m_CMscommput_PortOpen(1);//打开串口
static CString str("9600,n,8,1");
m_CMscommget_Input();
m_CMscommput_RThreshold(1);
m_CMscommput_Settings(str);
static char ch[10];
CString str1("com");
for(int i=1;i<10;i++)
{
itoa(i,ch,10);
m_CComboBoxAddString(str1+ch);
}
m_CComboBoxSetCurSel(0);
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void C串口Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAboutDoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void C串口Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dcGetSafeHdc()), 0);
// 使图标在工作区矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rectWidth() - cxIcon + 1) / 2;
int y = (rectHeight() - cyIcon + 1) / 2;
// 绘制图标
dcDrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
CWindowDC dc(this);
CFont font; //设置字体
CBrush brush;
brushCreateSolidBrush(255);
fontCreatePointFont(150,_T("华文行楷"));
dcSelectObject(&font);
dcSelectObject(&brush);
//dcTextOut(250,300,_T("大族激光软件中心"));
}
//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR C串口Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void C串口Dlg::OnBnClickedButton1()
{
static char ch1[10];
CString str("");
if(m_CMscommget_PortOpen())
m_CMscommput_PortOpen(false);
m_CMscommput_CommPort(m_Selection+1);
m_CMscommput_PortOpen(m_Selection+1);
strFormat("打开串口%d成功",m_Selection+1);
if(m_CMscommget_PortOpen())
{
MessageBox(str);
}
else
{
MessageBox("不能打串口");
}
//MessageBox(ch1);
// TODO: 在此添加控件通知处理程序代码
}
void C串口Dlg::OnSelchangeCombo2()
{
// TODO: 在此添加控件通知处理程序代码
//int m_Selection;
m_Selection=m_CComboBoxGetCurSel();
}
void C串口Dlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
/short m_short=m_CMscommget_CommPort();
CString str;
strFormat(_T("当前打开端口:%d"),m_short+1);
MessageBox(str);
CDialogEx::OnLButtonDblClk(nFlags, point);/
}
BEGIN_EVENTSINK_MAP(C串口Dlg, CDialogEx)
ON_EVENT(C串口Dlg, IDC_MSCOMM1, 1, C串口Dlg::OnCommMscomm1, VTS_NONE)
END_EVENTSINK_MAP()
void C串口Dlg::OnCommMscomm1()
{
VARIANT variant_inp;
COleSafeArray safearray_inp;
LONG len,k;
BYTE rxdata[2048]; //设置BYTE数组 An 8-bit integerthat is not signed
CString strtemp; if(m_CMscommget_CommEvent()==2) //事件值为2表示接收缓冲区内有字符
{ ////////以下你可以根据自己的通信协议加入处理代码
variant_inp=m_CMscommget_Input(); //读缓冲区
safearray_inp=variant_inp; //VARIANT型变量转换为ColeSafeArray型变量
len=safearray_inpGetOneDimSize(); //得到有效数据长度
for(k=0;k<len;k++) safearray_inpGetElement(&k,rxdata+k);//转换为BYTE型数组
for(k=0;k<len;k++) //将数组转换为Cstring型变量
{ BYTE bt=(char)(rxdata+k); //字符型
strtempFormat("%c",bt); //将字符送入临时变量strtemp存放
m_send+=strtemp; //加入接收编辑框对应字符串
}
}
UpdateData(FALSE);
}
void C串口Dlg::OnBnClickedButton2()
{
UpdateData();
m_CMscommput_Output((COleVariant) m_send);
SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE) | WS_EX_ACCEPTFILES);
}
void C串口Dlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
MessageBox("sfsfe");
CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<fstream>
#include<algorithm>
#define SPACE "\t\t\t"
using namespace std;
struct Record{
string name;
string tel;
public:
friend ostream& operator<<(ostream& os,const Record rec){
return os<<rec->name<<SPACE<<rec->tel<<endl;
};
friend istream& operator>>(istream& is,Record rec){
is>>rec->name;
is>>rec->tel;
return is;
}
static bool comp(string patten,int type,Record rec){
switch(type){
case 0: {return rec->name==patten;}break;
case 1: {return rec->tel==patten;}break;
}
return false;
}
static bool isvan(Record rec){
return (rec->name==""&&rec->tel=="");
}
};
class RecordList:public list<Record>
{
public:
friend ostream& operator<<(ostream& os,const RecordList &c_rl){
RecordList::const_iterator it=c_rlbegin();
while(it!=c_rlend()){
os<<it;
it++;
}
return os;
}
friend istream& operator>>(istream& is,RecordList &rl){
RecordList::const_iterator it;
while(!iseof()){
Record prec=new Record;
is>>prec;
if(Record::isvan(prec)) continue;
rllist<Record>::push_back(prec);
}
return is;
}
void clear();
iterator erase(iterator pos);
~RecordList(){
this->clear();
}
};
void RecordList::clear(){
RecordList::const_iterator it=this->begin();
while(it!=this->end()){
delete(it);
it++;
}
this->list<Record>::clear();
}
RecordList::iterator RecordList::erase(iterator pos){
delete(pos);
return list<Record>::erase(pos);
}
class AddressList{
protected:
RecordList recList;
public:
typedef RecordList::iterator Iterator;
//从通信录中寻找一个记录
virtual Iterator findRecord(string patten,int type,Iterator from);
virtual void addRecord(Record rec);
virtual void removeRecord(Iterator it);
virtual void editRecord(Record rec,Iterator it);
virtual void saveRecords(ostream& os);
virtual void loadRecords(istream& is);
virtual void addRecords(istream& is);
virtual ~AddressList();
const int size() const{return (int)recListsize();}
const void clear(){recListclear();}
Iterator begin(){return recListbegin();}
Iterator end() {return recListend();}
};
AddressList::Iterator AddressList::findRecord(string patten,int type,Iterator from){
Iterator it;
it=from;
while(it!=recListend()){
if(Record::comp(patten,type,it)){
return it;
}
it++;
}
return it;
}
void AddressList::addRecord(Record rec){
recListpush_back(rec);
}
void AddressList::removeRecord(Iterator it){
recListerase(it);
}
void AddressList::editRecord(Record rec,Iterator it){
delete(it);
it=rec;
}
void AddressList::saveRecords(ostream& os){
os<<recList;
}
void AddressList::loadRecords(istream& is){
is>>recList;
}
void AddressList::addRecords(istream& is){
}
AddressList::~AddressList(){
recListclear();
}
class AddressBook : public AddressList{
protected:
bool isModified;//通信录是否已被修改还未保存
public:
AddressBook();
virtual ~AddressBook();
//开始通信录的用户界面 *** 作
virtual void start();
//菜单处理函数管理程序的用户界面 *** 作
virtual void handleMenu();
//显示记录
virtual void displayRecords();
//查询记录
virtual void queryRecord();
//添加记录
virtual void addRecord();
//保存记录
virtual void saveRecords();
//读取记录
virtual void loadRecords();
//结束程序
virtual void quit();
//清空当前记录信息
virtual void clear();
protected:
//菜单选择函数
char menuSelect();
//显示表头
void dispTable();
};
AddressBook::AddressBook(){
}
AddressBook::~AddressBook(){;}
char AddressBook::menuSelect(){
char a=0;
cin>>a;
if(a=='y'||a=='Y'){a='1';}
if(a=='n'||a=='N'){a='2';}
return a;
}
void AddressBook::start(){
cout << "\n\t 欢迎使用sjb版通讯录 ";
handleMenu();
}
void AddressBook::handleMenu(){
cout << "\n\n\t\t\t-- 菜单管理 --\n\n";
cout << "\tA -- 添加人员纪录 (Add Record)\n"
<< "\tF -- 查询纪录 (Find Record)\n"
<< "\tD -- 显示纪录 (Display Records)\n"
<< "\tL -- 从文本或标准输入流中加载纪录 (Load Records)\n"
<< "\tC -- 清空当前记录信息\n"
<< "\tS -- 保存记录 (Save Records)\n"
<< "\tQ -- 结束程序 (QUIT)\n";
switch(menuSelect()){
case 'A':
case 'a':addRecord();break;
case 'F':
case 'f':queryRecord();break;
case 'D':
case 'd':displayRecords();break;
case 'L':
case 'l':loadRecords();break;
case 'C':
case 'c':clear();break;
case 'S':
case 's':saveRecords();break;
case 'Q':
case 'q':quit();break;
}
handleMenu();
}
void AddressBook::displayRecords(){
cout<<"姓名"<<SPACE<<"电话"<<endl;
AddressList::saveRecords(cout);
cout<<"一共找到"<<size()<<"个对象。"<<endl;
cout<<"1"<<SPACE<<"返回"<<endl;
cout<<"2"<<SPACE<<"修改"<<endl;
cout<<"3"<<SPACE<<"删除"<<endl;
switch(menuSelect()){
case '1':break;
case '2':{
if(!size()){
cout<<"记录为0,无法修改。"<<endl;
break;
}
cout<<"要修改第几个?"<<"1~"<<size()<<endl;
int i;
cin>>i;
if(i<1||i>size()){
break;
}
Record prec=new Record;
cout<<"姓名:"<<'\n'<<"电话:"<<'\n';
cin>>prec;
Iterator it=recListbegin();
while(i!=1){
it++;
i--;
}
editRecord(prec,it);
}break;
case'3':{
if(!size()){
cout<<"记录为0,无法修改。"<<endl;
break;
}
cout<<"要删除第几个?"<<"1~"<<size()<<endl;
int i;
cin>>i;
if(i<1||i>size()){
break;
}
Iterator it=recListbegin();
while(i!=1){
it++;
i--;
}
removeRecord(it);
}break;
}
}
void AddressBook::addRecord(){
string name,tel;
cout << "\n输入名字: ";
cin >> name;
cout << "输入电话: ";
cin >> tel;
Record temp=new Record;
temp->name=name;
temp->tel=tel;
AddressList::addRecord(temp);
cout<<"是否继续(Y/N)"<<endl;
switch(menuSelect()){
case '1':addRecord();break;
case '2':break;
}
}
void AddressBook::queryRecord(){
cout<<"1"<<SPACE<<"按姓名查找"<<endl;
cout<<"2"<<SPACE<<"按电话查找"<<endl;
int type=-1;
string patten;
switch(menuSelect()){
case '1':{
type=0;
cout<<"请输入姓名"<<endl;
cin>>patten;
}break;
case '2':{
type=1;
cout<<"请输入电话号码"<<endl;
cin>>patten;
}break;
}
Iterator it=begin();
list<Iterator> li;
cout<<"姓名"<<SPACE<<"电话"<<endl;
while((it=findRecord(patten,type,it))!=end()){
cout<<it;
lipush_back(it);
it++;
}
cout<<"一共找到"<<lisize()<<"个对象。"<<endl;
cout<<"1"<<SPACE<<"返回"<<endl;
cout<<"2"<<SPACE<<"修改"<<endl;
cout<<"3"<<SPACE<<"删除"<<endl;
switch(menuSelect()){
case'1':break;
case'2':{
if(!lisize()){
cout<<"记录为0,无法修改。"<<endl;
break;
}
cout<<"要修改第几个?"<<"1~"<<lisize()<<endl;
int i;
cin>>i;
Record prec=new Record;
cout<<"姓名:"<<'\n'<<"电话:"<<'\n';
cin>>prec;
list<Iterator>::const_iterator it=libegin();
while(i!=1){
it++;
i--;
}
editRecord(prec,it);
}break;
case'3':{
if(!lisize()){
cout<<"记录为0,无法修改。"<<endl;
break;
}
cout<<"要删除第几个?"<<"1~"<<lisize()<<endl;
int i;
cin>>i;
list<Iterator>::const_iterator it=libegin();
while(i!=1){
it++;
i--;
}
removeRecord(it);
}break;
}
}
void AddressBook::saveRecords(){
cout<<"1"<<SPACE<<"使用默认文件名。"<<endl;
cout<<"2"<<SPACE<<"使用自定义文件名。"<<endl;
cout<<"3"<<SPACE<<"返回"<<endl;
switch(menuSelect()){
case '1':{
ofstream file("default",ios::app);
AddressList::saveRecords(file);
fileclose();
}break;
case '2':{
cout<<"请输入您定义的文件名:"<<endl;
string fname;
cin>>fname;
ofstream file(fnamec_str(),ios::app);
AddressList::saveRecords(file);
fileclose();
}break;
case '3':break;
}
}
void AddressBook::loadRecords(){
cout<<"1"<<SPACE<<"使用默认文件。"<<endl;
cout<<"2"<<SPACE<<"使用自定义文件。"<<endl;
cout<<"3"<<SPACE<<"返回"<<endl;
switch(menuSelect()){
case '1':{
cout<<"1"<<SPACE<<"覆盖当前内容"<<endl;
cout<<"2"<<SPACE<<"追加到当前文件"<<endl;
switch(menuSelect()){
case '1':
AddressList::clear();break;
case '2':break;
}
ifstream file("default");
AddressList::loadRecords(file);
fileclose();
}break;
case '2':{
cout<<"请输入文件名:"<<endl;
string fname;
cin>>fname;
ifstream file(fnamec_str());
AddressList::loadRecords(file);
fileclose();
}break;
case '3':break;
}
}
void AddressBook::clear(){
cout<<"是否要清除内存中所有内容?(Y/N)"<<endl;
switch(menuSelect()){
case '1':AddressList::clear();break;
case '2':break;
}
}
void AddressBook::quit(){
cout<<"是否要保存文件?(Y/N)"<<endl;
switch(menuSelect()){
case'1':saveRecords();break;
case'2':break;
}
exit(0);
}
int main(int argc, char argv[])
{
AddressBook a;
astart();
system("PAUSE");
return EXIT_SUCCESS;
}
刚好我在弄crc校验。给你一段代码。我也是冲网上抄过来的。验证过了。
unsigned short crc16;
static uchar code auchCRCHi[256] = {
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40,
0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1,
0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0,
0x80, 0x41, 0x00, 0xC1, 0x81, 0x40
};
// CRC 低位字节值表
static uchar code auchCRCLo[256] = {
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06,
0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04, 0xCC, 0x0C, 0x0D, 0xCD,
0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09,
0x08, 0xC8, 0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A,
0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC, 0x14, 0xD4,
0xD5, 0x15, 0xD7, 0x17, 0x16, 0xD6, 0xD2, 0x12, 0x13, 0xD3,
0x11, 0xD1, 0xD0, 0x10, 0xF0, 0x30, 0x31, 0xF1, 0x33, 0xF3,
0xF2, 0x32, 0x36, 0xF6, 0xF7, 0x37, 0xF5, 0x35, 0x34, 0xF4,
0x3C, 0xFC, 0xFD, 0x3D, 0xFF, 0x3F, 0x3E, 0xFE, 0xFA, 0x3A,
0x3B, 0xFB, 0x39, 0xF9, 0xF8, 0x38, 0x28, 0xE8, 0xE9, 0x29,
0xEB, 0x2B, 0x2A, 0xEA, 0xEE, 0x2E, 0x2F, 0xEF, 0x2D, 0xED,
0xEC, 0x2C, 0xE4, 0x24, 0x25, 0xE5, 0x27, 0xE7, 0xE6, 0x26,
0x22, 0xE2, 0xE3, 0x23, 0xE1, 0x21, 0x20, 0xE0, 0xA0, 0x60,
0x61, 0xA1, 0x63, 0xA3, 0xA2, 0x62, 0x66, 0xA6, 0xA7, 0x67,
0xA5, 0x65, 0x64, 0xA4, 0x6C, 0xAC, 0xAD, 0x6D, 0xAF, 0x6F,
0x6E, 0xAE, 0xAA, 0x6A, 0x6B, 0xAB, 0x69, 0xA9, 0xA8, 0x68,
0x78, 0xB8, 0xB9, 0x79, 0xBB, 0x7B, 0x7A, 0xBA, 0xBE, 0x7E,
0x7F, 0xBF, 0x7D, 0xBD, 0xBC, 0x7C, 0xB4, 0x74, 0x75, 0xB5,
0x77, 0xB7, 0xB6, 0x76, 0x72, 0xB2, 0xB3, 0x73, 0xB1, 0x71,
0x70, 0xB0, 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92,
0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, 0x9C, 0x5C,
0x5D, 0x9D, 0x5F, 0x9F, 0x9E, 0x5E, 0x5A, 0x9A, 0x9B, 0x5B,
0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89, 0x4B, 0x8B,
0x8A, 0x4A, 0x4E, 0x8E, 0x8F, 0x4F, 0x8D, 0x4D, 0x4C, 0x8C,
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42,
0x43, 0x83, 0x41, 0x81, 0x80, 0x40
};
//CRC校验的函数
unsigned short CRC16(unsigned char puchMsg, unsigned short usDataLen)
{
unsigned char uchCRCHi = 0xFF ; / 高CRC字节初始化 /
unsigned char uchCRCLo = 0xFF ; / 低CRC 字节初始化 /
unsigned uIndex ; / CRC循环中的索引 /
while (usDataLen--) / 传输消息缓冲区 /
{
uIndex = uchCRCHi ^ puchMsg++ ; / 计算CRC /
uchCRCHi = uchCRCLo ^ auchCRCHi[uIndex] ;
uchCRCLo = auchCRCLo[uIndex] ;
}
return (uchCRCHi << 8 | uchCRCLo) ;
}
调用方式:dd=CRC16(tmp,x);
以上就是关于用C语言编写一个通讯录管理系统全部的内容,包括:用C语言编写一个通讯录管理系统、求C++ C语言大神帮忙弄一个串口通信的代码、C++通讯录的源代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)