Carleton University - SYSC 2006
get_route_info()
Assignment 1 - Spring 2025The goal of get_route_info() is to read pre-computed routing information from the file routeinfo.txt. Each line in this file contains the source node, destination node, next hop, and cost — all separated by semicolons. For example, the file might look like this:
nodeA;nodeB;nodeB;5
nodeA;nodeC;nodeB;8
nodeA;nodeD;nodeB;12
nodeB;nodeC;nodeC;3
nodeC;nodeD;nodeD;4Each line means: To reach the destination from the source node, forward the packet to the next hop with the given cost.
How do we do this?
To load routing info from the file and store it in the routing table, you need to:
File I/O:
Open the file using
fopen().
Input Parsing:
Use
fgets()to read each line.Use
sscanf()to extract the source node, destination node, next hop, and cost.
Routing Table Update:
Loop through the list of nodes to find the source node.
Then loop again to find the destination node index.
Store the destination, next hop, and cost in the routing table at the correct position.
Return:
Return
0on success, or1if 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.