CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

get_link_info()

Assignment 1 - Spring 2025

The goal of get_link_info() is to read link information from the file linkinfo.txt.
Each line in this file contains two node names (representing a connection between them), followed by the cost of the connection and the bandwidth — all separated by semicolons. For example, the file might look like this:

nodeA;nodeB;5;100
nodeA;nodeC;10;80
nodeB;nodeD;7;80
nodeC;nodeD;4;100

Each line means that two nodes are connected, and the link between them has a cost and a bandwidth.


How do we do this?

To read the links from the text file, you need to:

  1. File I/O:

    • Open the file using fopen().

  2. Input Parsing:

    • Use fgets() to read each line.

    • Use sscanf() to extract the two node names, the cost, and the bandwidth.

  3. Node Validation:

    • Loop through the existing list of nodes (from get_node_info()).

    • Check that both nodes mentioned in each line actually exist in the node list.

    • If either node doesn't exist, print an error message.

  4. Output:

    • For each valid link, print a line showing the connection, cost, and bandwidth.

    • If a link is invalid (one or both nodes not found), print an error message like:

      Error: Invalid nodes found in linkinfo.txt -> [nodeX] or [nodeY] does not exist in nodeinfo.txt
  5. Return:

    • Return 0 on success, or 1 if the file could not be opened.

Members only

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.