C Program to Abbreviate a String

C Program to Abbreviate a String . Compiled in Dev C++

#include<stdio.h>
#include<string.h>
#include<conio.h>
void string_abbreviation(char [],char []);
main()
{
      char text[30],target[30];
      printf("\nProgram to Abbreviate a String \n");
      printf("\n--------------------------------\n\n\n");
      printf("Enter Text : ");                                                   
      gets(text);
      
      string_abbreviation(text,target);
      
      printf("\nAbbreviation of string '%s' is : %s",text,target);
      
      getch();
      
}


          
void string_abbreviation(char a[],char b[])
     {
       char *p;
       int length,i,k=0;
       length=strlen(a);
       
       b[k]=a[0];
       k++;
      
       
       for(i=0;i<length;i++)
       {
            p=&a[i];
            
          
            
            if(*p==' ')
            {
                
                b[k]=*(p+1);  
                k++;         
            }            
           
           
                              
        }  
        
        b[k]='\0';
        strupr(b);
          
     }

Output

abbrevviation

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s