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

  • Home
  • SEARCH
  • 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 1073119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:56:56+00:00 2026-05-16T20:56:56+00:00

I’m working on a tasklist program to brush up on my C before I

  • 0

I’m working on a tasklist program to brush up on my C before I take a class. I have two structs, task and tasklist.

Here is the task struct:

typedef struct task
{
  char name[100];
  bool completed; /* bool is described as an enum in an included header file */
  date due_date; /* date is a described as a struct in an included header file */
} task;

I have the following working functions:

  • List item
  • init_tasklist(): initialize tasklist variables
  • add_task(): add task to the tasklist
  • delete_task(): delete the given task from the tasklist
  • print_tasklist(): print out the tasklist similar to a normal todo list with a checkbox, name and due date for each item
  • delete_tasklist(): delete the given tasklist
  • print_task(): print out the details of a given task

My question has to do with which variables to have as parameters to functions and what to return.

I would like to use this tasklist for a cli interface and then change it to a GUI, so I would like to make that an easy switch.

At first, I had add_task() malloc()-ing a new task and returning a pointer to that task, and then delete_tasklist() recursively went through and free()-ed the memory as it deleted the tasklist. I got this approach from my experience with OOP and Java.

What’s the best way to design this in C?

Should the add_task() function take a task struct to add to the list or perhaps just the variables that should be in the task and have the add_task() function initialize it?

Should I write a get_task() function that returns the pointer to a task with the given name for functions like print_task() and delete_task(), which would take a task pointer, or should those take char pointers and find the task themselves?

Any guidance on how to design the I/O of these functions would be very helpful.

  • 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-16T20:56:57+00:00Added an answer on May 16, 2026 at 8:56 pm

    Since your data structure is a list of tasks, it’s cleaner to call add_task() with a task struct (The tasklist doesn’t have to know about the internal representation of the task struct).

    It might be handy to have a create_task() method which receives the task fields and returns a task struct filled with these fields.

    Logically, create_task() belongs to the task struct, while add_task() belongs to task list. (e.g. If you were writing in OO language, you would have TaskList.AddTask(task), and Task.Create(name, dd, isCompleted))

    The get_task() method, is something that you will need to use more than once (as you stated, print_stack(), delete_stack()).
    Encapsulating this code in a function is obviously better than code duplication. (e.g. if you find a bug in this code, you’ll have to fix it once instead of searching everywhere in your program). Also, since this code has a “stand-alone meaning”, it’s convenient to have a function which performs it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.