Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 901757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:36:26+00:00 2026-05-15T15:36:26+00:00

I’m new to C++ and was working on an assignment for a class. We

  • 0

I’m new to C++ and was working on an assignment for a class. We were given a .txt file, have to read information from it, and store it in a linked list, and then print it out to the user. After hours of trying to manipulate the examples we were given, and another couple hours of trying to write the code from scratch, I’m getting closest with a little of both.

The file is called payroll.txt and has about 30 or so lines in this type of format:
Clark Kent 55000 2500 0.07
Lois Lane 65000 1000 0.06
Tony Stark 70000 1500 0.05

Our professor is really big on commenting on our code, so I hope it helps. This is my code:

#include <cstdlib>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

#define MAX_STR         100

/* Structure Definition */
typedef struct employeeType Employ;
struct employeeType {
   char first[MAX_STR];   /* first name */
   char last[MAX_STR];    /* last name */
   int salary;            /* salary */
   int bonus;             /* bonus */
   double deduc;          /* percent deduction */
   Employ *next;
};

/* operations on the data */
Employ *ReadRecord(); 
void PrintRecord(Employ *);

main()
{{ 
Employ *head, *tail, *newp, *tmp;
head = tail = newp = tmp = NULL;
FILE *in;                     /* file description */

/* open a file, check if it's there */
if( (in = fopen( "payroll.txt", "r" )) == NULL )
{
  printf( "Error opening file\n" );
  exit(1);
}
while( newp = ReadRecord() ) 
{
    /* Add object to the list */ 
    if( head == NULL ) 
    { 
        /* Beginning of the list */
        head = newp;

        /* Current record */
        tail = newp; 
    } 
    else 
    { 
        /* Previous record reference to new record */
        tail->next = newp;

        /* Current record */
        tail = newp; 
    }
}

/* End of the list */
tail->next = NULL; 

/* Loop through the list */
for( tmp=head; tmp!=NULL; tmp=tmp->next ) 
{ 
    PrintRecord( tmp ); 
} 

Now when I compile, I get the errors:
[Linker error] undefined reference to ReadRecord()
[Linker error] undefined reference to PrintRecord(employeeType*)

I’m almost sure that the ReadRecord and PrintRecord commands he gave us in the example are Pseudo Code meant to mess us up, but I have no idea what could go there. I’ve been pouring over multiple textbooks and searching for a simple way to fix linker errors online, and have run out of ideas.

If anyone could help me out/point me in the right direction it would be greatly appreciated. A link to a webpage with more info on linked lists and Linker Errors would be even more awesome.

Thanks,
Adam

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:36:27+00:00Added an answer on May 15, 2026 at 3:36 pm

    The linker is complaining that you have referenced the functions ReadRecord and PrintRecord, but you haven’t written them yet. You can write these functions at the end of the current file. You can start with this template:

    // Read a record from the file and parse the data into a structure
    Employ *ReadRecord (void) {
    
        // Use fgets() to read a line from the file
    
        // Create a new Employ object to hold the data
    
        // Use sscanf() to parse individual fields out of the string
        //   and store them in the new Employ object
    
        // Return a pointer to the new Employ object
    
        return (Employ*)NULL;
    }
    
    // Print the information from the structure to the screen
    void PrintRecord (Employ *ptr) {
    
        // Use printf() to display the content of each field
    
        return;
    }
    

    With these function templates added to the file, the linker should no longer complain about undefined references (since the functions have now been created). However, the code won’t work correctly since these functions don’t actually do anything. You will need to fill in the body of the functions (based on the details of your assignment).

    Edit: I have included a few hints (as code comments) in case you don’t know where to begin. For detailed help on parsing data from a text file or displaying information to the screen, consult your textbook (it should have many examples that would help you in this instance).

    Update: A few links:

    • A PDF guide to the basics of linked lists
    • An example implementation of a linked list
    • An example of parsing data from a text file in C
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.