CJCoding With Joseph
15free / daySign inCreate account

Carleton University - SYSC 2006

get_node_info()

Assignment 1 - 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


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

    • Use a counter (passed as a pointer) to keep track of how many nodes are read.

    • Ensure that this count does not exceed the constant NODE_MAX.

  4. Error Handling:

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

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