9 Jan 2015

PROGRAM FOR ABBRIVIATION FORM OF GIVEN STRING



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
 {
  clrscr();
  char s1[50],s2[50];
  int i,j,l,k=0,p=0,m=0;
  printf("Enter any string:-\n");
  gets(s1);
  l=strlen(s1);
  s2[m]=s1[0];
  m++;
  s2[m]='.';
  m++;
  for(i=0;i<l;i++)
   {
    if(s1[i]==' ')
     k++;
    }
  for(i=0;i<l;i++)
    {
      if(s1[i]==' ')
      {
          p++;
          if(p==k)
           {
             for(j=i+1;j<l;j++)
              {
               s2[m]=s1[j];
               m++;
              }
            }
           else
            {
             s2[m]=s1[i+1];
             m++;
             s2[m]='.';
             m++;
            }
          }
      }
     s2[m]='\0';
     printf("\nThe abbreviated form is:-\n");
     printf("%s",s2);
     getch();
    }

No comments:

Post a Comment