Question
*Must be in C. The program takes a linked list of words and counts the number of words that are all lowercase or all uppercase.
*Must be in C. The program takes a linked list of words and counts the number of words that are all lowercase or all uppercase. I will attach the code below. All that needs to be done is the function countSame.
#include
typedef struct words { char *name; struct words *next; } Words;
void print(Words *); Words *add(Words *, char *); int countSame(Words *);
int main(void) { char input[100]; Words *myList = NULL; printf("Enter a word : "); scanf("%s", input); while (strcmp(input, "xxx") != 0) { myList = add (myList, input); printf("Enter a word or 'xxx' to exit : "); scanf("%s", input); } printf(" The list is "); print(myList); printf(" "); printf(" countSame returns %d ", countSame(myList) ); return 0; } void print(Words *ptr) { while (ptr) { printf("%s ", ptr->name); ptr = ptr->next; } return; }
Words *add(Words *ptr, char *name) { Words *newNode = malloc( sizeof(Words) ); newNode->name = malloc( strlen(name) + 1 ); strcpy(newNode->name, name); newNode->next = ptr; return newNode; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started