Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Change my code, so that it doesn t bring any error when I compile it with g + + compiler. Also, I want my code
Change my code, so that it doesnt bring any error when I compile it with g compiler. Also, I want my code to be in a C programming language format as much as possible. Here is my code about distance vector:
#include
#include
#include
#define MAXNODES
#define INFINITY
typedef struct
int costMAXNODES;
int nexthopMAXNODES;
RoutingTable;
int numnodes;
int graphMAXNODESMAXNODES;
RoutingTable rtMAXNODES;
void readtopologyconst char filename
FILE file fopenfilenamer;
if file
printfError: open input file.
;
exit;
fscanffiled &numnodes;
for int i ; i numnodes; i
for int j ; j numnodes; j
if i j
graphij;
else
graphij INFINITY;
int node node cost;
while fscanffiled d d &node &node &cost EOF
graphnodenode cost;
graphnodenode cost;
fclosefile;
void initializeroutingtable
for int i ; i numnodes; i
for int j ; j numnodes; j
if i j
rticostj;
rtinexthopj i;
else if graphij INFINITY
rticostj graphij;
rtinexthopj j;
else
rticostj INFINITY;
rtinexthopj;
void updateroutingtable
int updated;
do
updated ;
for int i ; i numnodes; i
for int j ; j numnodes; j
for int k ; k numnodes; k
if rticostj rticostk rtkcostj
rticostj rticostk rtkcostj;
rtinexthopj rtinexthopk;
updated ;
while updated;
void printroutingtableFILE output int src
for int i ; i numnodes; i
fprintfoutputd d d
i rtsrcnexthopi rtsrccosti;
fprintfoutput
;
void readmessagesconst char filename FILE output
FILE file fopenfilenamer;
if file
printfError: open input file.
;
exit;
int src dst;
char message;
while fscanffiled d &src &dst EOF
fgetsmessage sizeofmessage file;
messagestrlenmessage; Remove newline character
if rtsrccostdst INFINITY
fprintfoutput "from d to d cost infinite hops unreachable message s
src dst message;
else
fprintfoutput "from d to d cost d hops", src dst rtsrccostdst;
int hop src;
while hop dst
fprintfoutputd hop;
hop rthopnexthopdst;
fprintfoutput message s
message;
fclosefile;
void applychangesconst char filename
FILE file fopenfilenamer;
if file
printfError: open input file.
;
exit;
int node node cost;
while fscanffiled d d &node &node &cost EOF
if cost
graphnodenode INFINITY;
graphnodenode INFINITY;
else
graphnodenode cost;
graphnodenode cost;
fclosefile;
int mainint argc, char argv
if argc
printfusage: distvec topologyfile messagesfile changesfile
;
return ;
readtopologyargv;
FILE output fopenoutputdvtxtw;
if output
printfError: open output file.
;
return ;
initializeroutingtable;
updateroutingtable;
for int i ; i numnodes; i
printroutingtableoutput i;
readmessagesargv output;
applychangesargv;
initializeroutingtable;
updateroutingtable;
for int i ; i numnodes; i
printroutingtableoutput i;
readmessagesargv output;
fcloseoutput;
printfComplete Output file written to outputdvtxt
;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started