/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define N 30
#define M 199
typedef struct node
{ int countwords;
struct node *next;
} COUNT;
struct occurrence
{
char word[30];
int count;
COUNT * ocurrence_list_thehead;
};
struct occurrence occurrences[30];
COUNT *first = NULL;
COUNT *last = NULL;
int counter=0;
int main()
{
COUNT *node=NULL;
char textin[N+1];
printf("please give a word, or type exit to end\n");
while(1) {
node=malloc(sizeof(COUNT));
if (node==NULL)
{
printf("Cannot allocate memory");
return 1;
}
fflush(stdin);
fgets(textin, sizeof(textin), stdin);
if (strcmp(textin , "exit") == 0)
break;
else
{
node->countwords = strlen(textin);
node->next=NULL;
if (first!=NULL){
last->next=node;
last=node;
}
else {
first=node;
last=node;
}
struct occurrence *occ = &(occurrences[counter]);
occ->ocurrence_list_thehead-> countwords = strlen(textin);
counter++;
}
node=first;
while (node!=NULL){
printf ("\n %d length of string", node->countwords);
node=node->next;
}
return 0;
}
}