Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <string.h>
- struct Node {
- char data[80];
- Node* next;
- };
- void AddNode(Node*& first, char* str)
- {
- if (first == NULL)
- {
- first = new Node;
- strcpy(first->data, str);
- first->next = NULL;
- }
- else
- {
- Node* cur = first;
- first = new Node;
- strcpy(first->data, str);
- first->next = cur;
- }
- }
- void PrintList(Node* first)
- {
- while (first != NULL)
- {
- printf("%s ", first->data);
- first = first->next;
- }
- }
- int FindWords(Node* first)
- {
- int cnt = 0;
- while (first != NULL)
- {
- if (first->data[0] == first->data[strlen(first->data) - 1])
- {
- printf("%s ", first->data);
- cnt++;
- }
- first = first->next;
- }
- return cnt;
- }
- void ClearMemory(Node*& first)
- {
- while (first != NULL)
- {
- Node* tmp = first;
- first = first->next;
- delete tmp;
- }
- }
- int main()
- {
- Node* first = NULL;
- char str[80];
- char* ptr;
- puts("Enter the word sequence:");
- gets_s(str);
- ptr = strtok(str, " ,.");
- while (ptr != NULL)
- {
- AddNode(first, ptr);
- ptr = strtok(NULL, " ,.");
- }
- puts("\nThe formed list:");
- PrintList(first);
- puts("\n\nWords with the same beginning/ending:");
- printf("\nNumber of words: %d", FindWords(first));
- ClearMemory(first);
- puts("\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement