CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

get_node_info()

Assignment 2 - Spring 2025

The goal of get_node_info() is to read node information from the file nodeinfo.txt. Each line in this file contains a node name and an IP address separated by a semicolon. For example, the file looks like this:

nodeA;10.1.1.1
nodeB;10.1.1.2
nodeC;10.1.1.3
nodeD;10.1.1.4

Each line means there is a node in the network named nodeA with IP address 10.1.1.1, and so on.


How do we do this?

To read the nodes 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 node name and IP address from each line.

  3. Node Insertion (Linked List):

    • For each node, create a new node_t structure.

    • Insert the new node into a linked list in alphabetical order by name.

  4. Error Handling:

    • If the file cannot be opened, print an error message and return a non-zero value.

    • Otherwise, return 0 on success.

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.