Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please review following codes and change the code so that it satisfies the output file rule. / / code #include #include #include #include #define INF
Please review following codes and change the code so that it satisfies the output file rule.
code
#include
#include
#include
#include
#define INF INTMAX
typedef struct
int node;
int cost;
Edge;
typedef struct
int from;
int to;
char msg;
Message;
typedef struct
int node;
int node;
int cost;
Change;
typedef struct
Edge edges;
int size;
int capacity;
EdgeList;
void addedgeEdgeList list, int node, int cost;
void dijkstraint src EdgeList graph, int n int dist, int parent;
void printroutingtableint n int parent, int dist, FILE out;
void processtopologyconst char filename, int n EdgeList graph;
void processmessagesconst char filename, Message messages, int messagecount;
void processchangesconst char filename, Change changes, int changecount;
void updategraphEdgeList graph, Change change;
void addedgeEdgeList list, int node, int cost
if listsize listcapacity
listcapacity ;
listedges Edgerealloclistedges, listcapacity sizeofEdge;
if listedges
perrorFailed to realloc edges";
exitEXITFAILURE;
listedgeslistsizenode node;
listedgeslistsizecost cost;
listsize;
void dijkstraint src EdgeList graph, int n int dist, int parent
int visited intmallocn sizeofint;
if visited
perrorFailed to malloc visited";
exitEXITFAILURE;
for int i ; i n; i
disti INF;
parenti;
visitedi;
distsrc;
for int i ; i n; i
int u ;
for int j ; j n; j
if visitedj && u distj distu
u j;
if u distu INF break;
visitedu;
for int j ; j graphusize; j
Edge edge graphuedgesj;
int v edge.node;
int weight edge.cost;
if distu weight distv
distv distu weight;
parentv u;
freevisited;
void printroutingtableint n int parent, int dist, FILE out
for int i ; i n; i
if disti INF continue;
fprintfoutd d d
i parenti disti;
void processtopologyconst char filename, int n EdgeList graph
FILE in fopenfilenamer;
if in
perrorFailed to open topology file";
exitEXITFAILURE;
if fscanfind n
perrorFailed to read the number of nodes";
fclosein;
exitEXITFAILURE;
graph EdgeListmallocn sizeofEdgeList;
if graph
perrorFailed to malloc graph";
fclosein;
exitEXITFAILURE;
for int i ; i n; i
graphiedges Edgemalloc sizeofEdge;
if graphiedges
perrorFailed to malloc edges";
fclosein;
exitEXITFAILURE;
graphisize ;
graphicapacity ;
int u v cost;
while fscanfind d d &u &v &cost EOF
addedge&graphu v cost;
addedge&graphv u cost;
fclosein;
void processmessagesconst char filename, Message messages, int messagecount
FILE in fopenfilenamer;
if in
perrorFailed to open messages file";
exitEXITFAILURE;
messagecount ;
messages Messagemalloc sizeofMessage;
if messages
perrorFailed to malloc messages";
fclosein;
exitEXITFAILURE;
char line;
while fgetsline sizeofline in
int u v;
char msg;
if sscanflined d
&u &v msg
fprintfstderr "Error reading message: s line;
continue;
messagesmessagecountfrom u;
messagesmessagecountto v;
strcpymessagesmessagecountmsg msg;
messagecount;
fclosein;
void processchangesconst char filename, Change changes, int changecount
FILE in fopenfilenamer;
if in
perrorFailed to open changes file";
exitEXITFAILURE;
changecount ;
changes Changemalloc sizeofChange;
if changes
perrorFailed to malloc changes";
fclosein;
exitEXITFAILURE;
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