Carleton University - SYSC 2006
get_node_info()
Assignment 1 - Spring 2025The 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.4How do we do this?
To read the nodes from the text file, you need to:
File I/O:
Open the file using
fopen().
Input Parsing:
Use
fgets()to read each line.Use
sscanf()to extract the node name and IP address from each line.
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.
Error Handling:
If the file cannot be opened, print an error message and return a non-zero value.
Return
0on success.
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.