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

struct node {
    int data;
    struct node* link;
};

void count_of_nodes(struct node* head);

int main() {
    struct node* head = malloc(sizeof(struct node));
    head->data = 7;
    head->link = NULL;

    struct node* now = malloc(sizeof(struct node));
    now->data = 9;
    now->link = NULL;
    head->link = now;

    struct node* last = malloc(sizeof(struct node));
    last->data = 11;
    last->link = NULL;
    head->link->link = last;

    count_of_nodes(head);

    return 0;
}

void count_of_nodes(struct node* head) {
    int count = 0;
    if (head == NULL) {
        printf("linked list is empty");
    }
    struct node* ptr = NULL;
    ptr = head;
    while (ptr != NULL) {
        count++;
        ptr = ptr->link;
    }
    printf("%d", count);
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: