This problem involves a linked list where each node stores a

This problem involves a linked list where each node stores a symbol (a string of length at most 15) along with a pointer to the next element. Thus, the struct definition for each node of the list is as follows: Write a function int count (struct listnode *p, int maxien), where parameter p is a pointer to the head of the list. Your function must return the number of nodes in the list where the length of the string stored is at most the value given by parameter maxlen. You need to show only the C code for the above function. You need to perform basic error checking. You don\'t need to include comments in your code.

Solution

Here is the code for you:

#include <stdio.h>
#include <string.h>
#define SIZE 15
struct listnode
{
char symbol[SIZE+1];
struct listnode *next;
};

int count(struct listnode *p, int maxlen)
{
int c = 0;
while(p != NULL)
{
if(strlen(p->symbol) <= maxlen)
c++;
}
return c;
}

If you need any refinements, just get back to me.

 This problem involves a linked list where each node stores a symbol (a string of length at most 15) along with a pointer to the next element. Thus, the struct

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site