Count the number of strings from a list of strings with repetition

The strings or names should be arranged in alphabetical order or dictionary order along with the count or number of times the string repeated in the list.



Consider the following input:

4
indiaeduservices
coderegister
sathish
coderegister

Input explanation:

First line gives the number of strings supplied
Followed by strings in each line

Following is the output we should get:

coderegister 2
indiaeduservices 1
sathish 1

Output explanation:

The strings or names should be arranged in alphabetical order or dictionary order along with the count or number of times the string repeated in the list.

Implementation:

#include <stdio.h>
#define MAX 100

void swap(char **s,char **v)
{
 char *temp;
 temp=*s;
 *s=*v;
 *v=temp;
}

int compare(char *s,char *v)
{
 while(*s && *s==*v)
  s++,v++;
 return (*s-*v);
}

int main(void) {
 char *s[MAX];
 int n;
 int i,j;
 int count;
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  *(s+i)=(char*)malloc(sizeof(char)*MAX);
  scanf("%s",*(s+i));
 }
 for(i=0;i<n-1;i++)
 {
  for(j=i+1;j<n;j++)
  {
   if(compare(*(s+i),*(s+j))>0)
   {
    swap((s+i),(s+j));
   }
  }
 }
 count=1;
 for(i=0;i<n-1;i++)
 {
  if(compare(*(s+i),*(s+i+1))==0)
   count++;
  else
  {
   printf("%s %d\n",*(s+i),count);
   count=1;
  }
 }
 printf("%s %d",*(s+i),count);
 return 0;
}