模拟Ethernet帧的发送 C语言代码调试 太难了!哪位大神来看看

qq_40367434 2021-01-03 03:57:31
源码
#include "stdafx.h"
#include "Ethernet.h"
#include "CSMA030390.h"
#include "cmath"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
#endif
static char THIS_FILE[] = __FILE__;
// The one and only application object
CWinThread *thread1,*thread2;//定义变量
DWORD ID1,ID2,Bus=0;//初始化共享内存
UINT aThread(LPVOID pParam);//线程A代表主机A
UINT bThread(LPVOID pParam);//线程B代表主机B
using namespace std;
CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
//CString strHello;
//strHello.LoadString(IDS_HELLO);
//cout << (LPCTSTR)strHello << endl;
thread1=AfxBeginThread(aThread,NULL);//启动线程A
ID1=thread1->m_nThreadID;//线程A的ID号
thread2=AfxBeginThread(bThread,NULL);
ID2=thread2->m_nThreadID;
getchar();
}

return nRetCode;
}


UINT aThread(LPVOID pParam)
{
int i=0;
int CollisionCounter=16;//冲突次数
double collisionWindow=0.005;//冲突窗口取0.005
int randNum=rand()%3;//随机数
Loop:if(Bus==0)
{
Bus=Bus|ID1;//或符号
Sleep(12);

if(Bus==ID1)
{
printf("%d Send Success/n/n",ID1);
Bus=0;
CollisionCounter=16;
Sleep(rand()%10);
i++;
printf("主机A发送成功次数=%d/n/n",i);
if(i<10)
goto Loop;
}
else
{
printf("%d Send Collision/n/n",ID1);
Bus=0;
CollisionCounter--;
if(CollisionCounter>0)
{
Sleep(randNum*(int)pow(2,(CollisionCounter>10)?10:CollisionCounter)*collisionWindow);
goto Loop;
}
else
printf("%ld send Failure/n/n",ID1);
}
}
goto Loop;
return 0;
}

UINT bThread(LPVOID pParam)
{
int j=0;
int CollisionCounter=16;
double collisionWindow=0.005;
int randNum=rand()%3;
Loop:if(Bus==0)
{
Sleep(2);
Bus=Bus|ID2;
Sleep(3);

if(Bus==ID2)
{
printf("%d Send Success/n/n",ID2);
Bus=0;
CollisionCounter=16;
Sleep(rand()%10);
j++;
printf("主机B发送成功次数=%d/n/n",j);
if(j<10)
goto Loop;
}
else
{
printf("%d Send Collision/n/n",ID2);
Bus=0;
CollisionCounter--;
if(CollisionCounter>0)
{
Sleep(randNum*(int)pow(2,(CollisionCounter>10)?10:CollisionCounter)*collisionWindow);
goto Loop;
}
else
printf("%ld send Failure/n/n",ID2);
}
}
goto Loop;
return 0;
}

错误:
Cannot open include file: 'stdafx.h': No such file or directory
Cannot open include file: 'Ethernet.h': No such file or directory
Cannot open include file: 'CSMA030390.h': No such file or directory

三个头文件的错误是这样的
把他们注释后,
错误是下面这样

--------------------Configuration: SendFrame - Win32 Debug--------------------
Compiling...
SendFrame.cpp
D:\sendTCP\SendFrame.cpp(11) : error C2143: syntax error : missing ';' before '*'
D:\sendTCP\SendFrame.cpp(11) : error C2501: 'CWinThread' : missing storage-class or type specifiers
D:\sendTCP\SendFrame.cpp(11) : error C2501: 'thread1' : missing storage-class or type specifiers
D:\sendTCP\SendFrame.cpp(11) : error C2501: 'thread2' : missing storage-class or type specifiers
D:\sendTCP\SendFrame.cpp(12) : error C2146: syntax error : missing ';' before identifier 'ID1'
D:\sendTCP\SendFrame.cpp(12) : error C2501: 'DWORD' : missing storage-class or type specifiers
D:\sendTCP\SendFrame.cpp(12) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

SendFrame.obj - 7 error(s), 0 warning(s)

...全文
290 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
gouyanfen 2021-01-03
  • 打赏
  • 举报
回复
头文件不可以注释掉就完事,找不到你找原因,解决掉它,应该是工程包含目录不对找不到 后面的错误都是因为没有正确找到定义出现的。

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧