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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:21:44+00:00 2026-05-26T09:21:44+00:00

so I’m creating a linked list counter for fun, here’s my program. WHAT I

  • 0

so I’m creating a linked list counter for fun, here’s my program.

WHAT I WANT:
I want it to give me the correct count

WHAT I GET:
The following errors:

linkedlist.c:12: warning: assignment from incompatible pointer type
linkedlist.c:14: warning: assignment from incompatible pointer type
linkedlist.c: In function ‘main’:
linkedlist.c:22: warning: assignment from incompatible pointer type
linkedlist.c:23: warning: assignment from incompatible pointer type
linkedlist.c:24: warning: assignment from incompatible pointer type
linkedlist.c:25: warning: assignment from incompatible pointer type

MY CODE
I realize that this isn’t a good way to instantiate a linked list. That doesn’t matter though, what I’m stressing is that my counter works.

I have made some amendments to my code. No, this is not a c++ program, it actually is a c program.

My program now works, but I would like to know why I receive so many warnings about an incompatible pointer type. Any ideas? I’m sure it’s a simple problem.

 #include <stdio.h>
typedef struct {
  int x;
  char *y;
 struct CELL *next;
} CELL;

  int list_length(CELL *head){
    int counter;
    CELL *current;
    if(head->next!=NULL){
    current=head->next;
    for(counter=1;current!=NULL;++counter){
      current=current->next;}}
    else
      return 0;
    return counter;}


main(){
  CELL a,b,c,d,e;
  a.next=&b;
  b.next=&c;
  c.next=&d;
  d.next=&e;
  e.next=NULL;
  int l=list_length(&a);
  printf("The list length is %d \n",l);
}
  • 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-26T09:21:44+00:00Added an answer on May 26, 2026 at 9:21 am

    First, to get this program to compile…

    1. CELL isn’t a type, so you need struct CELL in your type declarations
    2. A structure requires a semi-colon at the end
    3. use char * instead of string (string isn’t a C data type)

    As for the algorithm in list_length(), you want something more like this:

    int list_length(struct CELL *head)
    {
        int counter = 0;
        while (head) {
            head = head->next;
            ++counter;
        }
        return counter;
    }
    

    You should also note that your instantiate() function returns a pointer to stack-allocated memory resulting in undefined behavior. Move the code from instantiate() into the main function.

    Here is a complete working program:

    #include <stdio.h>
    
    struct CELL {
        struct CELL *next;
    };
    
    int list_length(struct CELL *head)
    {
        int counter = 0;
        while (head) {
            head = head->next;
            ++counter;
        }
        return counter;
    }
    
    int main(void)
    {
        struct CELL a, b, c, d, e;
        a.next = &b;
        b.next = &c;
        c.next = &d;
        d.next = &e;
        e.next = NULL;
        printf("The list length is %d \n", list_length(&a));
        return 0;
    }
    

    To fix the warnings in your latest iteration you need to declare CELL something like this:

    typedef struct CELL_ {
        int x;
        char *y;
        struct CELL_ *next;
    } CELL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I

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.