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 6474337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:34:32+00:00 2026-05-25T06:34:32+00:00

After taking the summer off from C programming, I’m back in the thick of

  • 0

After taking the summer off from C programming, I’m back in the thick of it for classes and am trying to catch up, particularly in pointers.

The current assignment has us converting a program from an array structure to a simple linked list. In order to refresh my memory, I’ve tried implementing it in a standalone program, but am running into trouble.

My code:

struct node{
  int val;
  struct node *next;
};

typedef struct node *item;

item newNode(void); //function prototype

void main(){
    item *cur, *itemList;
    int i;

    itemList=NULL;

    for (i=0; i<=10; i++){
        cur= newNode();
        cur->val=i;
        cur->next= itemList;

    }
}

item newNode(void) {
    item box;  /* the new object to return */

    box = (item) malloc (sizeof (struct node));

    if (box == NULL) {
        printf("ERROR: emalloc failed for new Box\n");
        exit(0);
    }

    /* initialize fields */
    box->val=0;

    return box;

}

The first error message is coming at cur= newBox() and is stating that an assigment from an incompatible pointer type is being made. I’m not sure why, since cur is a pointer to a node, and box is a structure. Where does the incompatible pointer come from?

  • 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-25T06:34:33+00:00Added an answer on May 25, 2026 at 6:34 am

    The first problem is that your doing item *cur, *itemList; which is a node**. Change that to item cur, itemList; to get node*‘s; you don’t need a pointer to a pointer to a node, just a pointer to a node.

    Another problem is that you’re setting all the next pointers of your nodes to itemList without setting itemList to cur at the end of each loop iteration (which will make itemList point to the beginning of the list at the end of the loop).

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

Sidebar

Related Questions

After taking a few years off from programming, I decided to start learning vb.net.
When I go back to school after Thanksgiving, I'll be taking a course in
I'm trying to allow user to rename file name, after taking picture, but I
After taking quite a long break from active coding I am just starting to
After taking all the required privileges from a user I want to display a
I am a student and after taking some introductory programming courses in Java, C,
After taking a look at this SO question and doing my own research, it
I have an Ant script running a standard -task after taking in an inputed
Some apps display an Add a caption in the Preview Screen after taking/selecting an
When I use the UIImagePickerController to take a picture, after taking the picture it

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.