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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:10:39+00:00 2026-05-26T23:10:39+00:00

So I’m trying to implement a cache in C. I have included a very

  • 0

So I’m trying to implement a cache in C. I have included a very slimmed down version of my code.

I keep getting this error:

prog.c: In function ‘addtolist’:
prog.c:29: warning: assignment from incompatible pointer type
prog.c:40: warning: assignment from incompatible pointer type
prog.c: In function ‘main’:
prog.c:72: warning: assignment from incompatible pointer type

from this code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct node_
{
    char * word;
    int filenumber;
    struct node * next;
};
typedef struct node_ * node;

node createnode()
{
    node head;
    head = malloc(sizeof(struct node_));
    head->word = NULL;
    head->next = NULL;
    return head;
}

unsigned int addtolist(node head, char * word, unsigned int limit, int fileno)
{
    unsigned int templimit = limit;
    node temp;
    node temphead = head;
    while(temphead->next != NULL)
    {
            temphead = temphead->next;
    }
    temp = malloc(sizeof(struct node_));
    temp->word =(char*) malloc(strlen(word)+ 1);
    strcpy(temp->word, word);
    temp->next = NULL;
    temp->filenumber = fileno;
    templimit = templimit - (strlen(word) + 1) - sizeof(struct node_)- sizeof(int);
    printf("templimit is size %u\n", templimit);
    if (templimit < limit && templimit > 0)
    {
            temphead->next = temp;
            limit = limit - strlen(word) - 1 - sizeof(struct node_)- sizeof(int);
            return limit;
    }
    else
    {
            free(temp->word);
            free(temp);
            return 0;
    }
}


int main()
{
    node newlist = createnode();
    int i = 0;

    unsigned int limit = 65;
    unsigned int temp = limit;

    while(temp > 0 && temp <= limit)
    {
        temp = addtolist(newlist, "Hello", temp, i);
        i++;
        printf("new limit is - \t%u\nfilenumber is - \t%d\n", temp,i);

    }
    node ptr = newlist;
    while(ptr->next != NULL)
    {
            printf("node %d contains the word %s\n", ptr->filenumber, ptr->word);
            ptr = ptr->next;
    }
    return 1;
}

I honestly can’t figure out what I’m doing wrong… My logic was that, since I was typedef’ing my struct as a pointer, after I created the struct in memory, I would be able to easily step through the ensuing list. Where was the flaw in my logic?

EDIT the initial problem was fixed (I forgot an underscore in my type declaration for struct node_ next;.

Now I’m having another problem: when I try to step through the list at the bottom of my code to print out the words contained in the list, I’m basically not able to step through the list. I keep outputting:

templimit is size 43
new limit is -  43
filenumber is -     1
templimit is size 21
new limit is -  21
filenumber is -     2
templimit is size 4294967295
new limit is -  0
filenumber is -     3
node 0 contains the word (null)
node 0 contains the word Hello

For some reason, it seems that my program isn’t storing my changes to my list in memory after the first iteration. Any ideas on what I’m doing wrong?

Once again, any help would be appreciated, and thanks.

  • 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-26T23:10:40+00:00Added an answer on May 26, 2026 at 11:10 pm

    Inside your structure definition you have struct node without the underscore.

    you’d better have a forward declaration

    typedef struct node node;
    

    and then declare your structure

    struct node {
     ...
     node *next;
    };
    

    no need to have this underscore stuff and hiding the * in a typedef. That only makes you mix things up easily.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have this code to decode numeric html entities to the UTF8 equivalent character.
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.