Home > Back-end >  Simulation of the Ethernet frame to send C code debugging is hard! What a great spirit
Simulation of the Ethernet frame to send C code debugging is hard! What a great spirit

Time:01-04

The source code
# include "stdafx. H"
# include "Ethernet. H"
# include "CSMA030390. H"
# include "cmath
"# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
# endif
The static char THIS_FILE []=__FILE__;
//The one and only The application object
Thread1 CWinThread * and * thread2;//define variables
DWORD ID1, ID2, Bus=0;//initialize the Shared memory
UINT aThread (LPVOID pParam);//thread A representative host A
UINT bThread (LPVOID pParam);//thread B on behalf of the host B
using namespace std;
CWinApp theApp;

using namespace std;

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

//initialize the MFC and the print and the error on failure
if (! AfxWinInit (: : GetModuleHandle (NULL), NULL, : : GetCommandLine (), 0))
{
//TODO: change the error code to suit your needs
Cerr & lt; <_T (" Fatal Error: MFC initialization failed ") & lt; NRetCode=1;
}
The else
{
//TODO: code your application 's behaviors here.
//cstrings strHello;
//strHello LoadString (IDS_HELLO);
//cout & lt; <(LPCTSTR) strHello & lt; Thread1=AfxBeginThread (aThread, NULL);//start the thread A
ID1=thread1 - & gt; M_nThreadID;//thread A ID number
Thread2=AfxBeginThread (bThread, NULL);
ID2=thread2 - & gt; M_nThreadID;
getchar();
}

Return nRetCode;
}


UINT aThread (LPVOID pParam)
{
int i=0;
Int CollisionCounter=16;//number of conflict
Double collisionWindow=0.005;//conflict window take 0.005
Int randNum=rand () % 3;//random number
Loop: the if (Bus==0)
{
Bus=Bus | ID1.//or symbol
Sleep (12);

If (Bus==ID1)
{
Printf (" % d Send Success/n/n ", ID1);
Bus=0;
CollisionCounter=16;
Sleep (rand () % 10);
i++;
Printf (" host A send success=% d/n/n ", I);
If (i<10)
Goto Loop;
}
The else
{
Printf (" % d Send a Collision/n/n ", ID1);
Bus=0;
CollisionCounter -;
If (CollisionCounter> 0)
{
Sleep (randNum * (2, ((int) pow CollisionCounter> 10)? 10: CollisionCounter) * collisionWindow);
Goto Loop;
}
The 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: the 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 (" host B send success=% d/n/n ", j);
If (j<10)
Goto Loop;
}
The else
{
Printf (" % d Send a Collision/n/n ", ID2);
Bus=0;
CollisionCounter -;
If (CollisionCounter> 0)
{
Sleep (randNum * (2, ((int) pow CollisionCounter> 10)? 10: CollisionCounter) * collisionWindow);
Goto Loop;
}
The else
Printf (" % ld send Failure/n/n ", ID2);
}
}
Goto Loop;
return 0;
}

Error:
Always open include file: 'stdafx. H: No to the file or directory
Always open include file: 'Ethernet. H: No to the file or directory
Always open include file: 'CSMA030390. H: No to the file or directory

Three header file error is
After their comments,
Mistakes are the following

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the 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 the 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), and 0 warning (s)

CodePudding user response:

Header file can not be commented out is finished, can't find you find the reason, get rid of it, should be a project directory contains no find
At the back of the mistakes because we could not find correct definition,
  • Related