CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

get_link_info()

Assignment 2 - 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, 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;100

Each 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:

  1. File I/O:

    • Open the file using fopen().

  1. Input Parsing:

    • `Use fgets() to read each line.

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

  2. 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_t linked list.

      • Print an error message.

    • Otherwise, print a valid link message.

  3. 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.

  4. Return:

    • Return 0 on success.

    • Return 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.