A program for finding a single number of words in a paragraph

This is a program for counting the number of individual words in a variable paraas input.

I tried this using a linked list.

Here the variable completeis an array that acts like a hash code and stores all the alphabets, and I associate a new word according to the hash, and if there is the same word, then I increase the count. This is the logic I followed.

But the fact is that the program is not included in a certain part of the code written for repeated words, and it does not increase the score.

This is my code that can help me with this.

#include<stdio.h> 
#include<conio.h>
#include<string.h>
#define NULL 0
struct wordcount 
{
char *s;
int count;
struct wordcount *next;
};
struct checkletter
{
char alph;
struct wordcount *next;
};
struct wordcount * create(char *);
main()
{
char *c,*s1,*intm;
char hastlet;
int hash[26],len,i,k=0,r,j,m=0,t,flag=0;
struct checkletter complete[26];
struct wordcount *node;
clrscr();
for(r=0;r<=25;r++)
{   complete[r].alph=r+97;
    complete[r].next=NULL;
}
for(r=0;r<=25;r++)
{
    printf("%c",complete[r].alph);
}
printf("\n");
printf("Enter the para :");
gets(c);
len=strlen(c);
    //arranging the words and putting them with count
for(i=0;i<len;i++)
{       k=0;
    intm='\0';
    if(c[i]==' ')
    {       for(j=m;j<i;j++)
        {
            intm[k]=c[j];
            k++;

        }
        intm[k]='\0';
        strcpy(s1,intm);
        m=k;
        m++;

        hastlet=s1[0];

        for(t=0;t<26;t++)
        {
            if(complete[t].alph==hastlet)
            {      
                node=complete[t].next;
                if(node==NULL)
                {      
                    complete[t].next=create(s1);
                    node=complete[t].next;
                    break;
                }
                else
                {   while(!strcmp(node->s,s1))
                    {
                        node=node->next;
                        if(node->next==NULL)
                        {   flag++;
                            break;
                        }
                    }

                    if(!strcmp(node->s,s1))
                        (node->count)+=1;
                    if(flag)
                    {   node->next=create(s1);
                    }
                }       break;
            }
        }


    }
}

//displaying the word that are counted

for(i=0;i<26;i++)
{   node=complete[i].next;
if(complete[i].next!=NULL)
while(1)
{   printf("%s---%d",node->s,node->count);
    if(node->next==NULL)
        break;

}
}



getch();
}

struct wordcount * create(char *y)
{
struct wordcount *newnode;
newnode->s=y;
newnode->count=0;
newnode->next=NULL;
return newnode;
}
+3
source share
1 answer

The following is not true:

char *c;
...
gets(c);

c gets undefined. c, , , .

intm.

fgets gets

+2

Source: https://habr.com/ru/post/1789289/


All Articles