Carleton University - SYSC 2006
get_link_info()
Assignment 2 - Spring 2025The goal of get_link_info() is to read link information from the file linkinfo.txt.
Each line in this file contains two node names, followed by a cost and bandwidth, all separated by semicolons. For example, a typical file might look like this:
nodeA;nodeB;5;100
nodeA;nodeC;10;80
nodeY;nodeD;5;100
nodeC;nodeD;4;100Each line means that two nodes are connected by a link with a certain cost and bandwidth.
Before accepting the link, we need to make sure both nodes exist in the current node list.
How do we do this?
To read the links from the text file, you need to:
File I/O:
Open the file using
fopen().
Input Parsing:
`Use
fgets()to read each line.Use
sscanf()to extract the two node names, cost, and bandwidth.
Node Validation:
Use
find_node()to check if each node exists in the linked list.If either node does not exist:
Add it to an
invalid_node_tlinked list.Print an error message.
Otherwise, print a valid link message.
Cleanup:
At the end, print out the invalid node list.
Free the invalid list using
free_invalid_list()and print a message for each deleted node.
Return:
Return
0on success.Return
1if the file could not be opened.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 25 more lessons in Carleton University - SYSC 2006.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.