Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This problem involves a linked list where each node stores a symbol (a string of

ID: 3930589 • Letter: T

Question

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 maxlen), 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.

Explanation / Answer

Here is the code for count() function:

#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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote