//this program will print short name
//for example : Nayan Konar will print as N.Konar
#include< stdio.h>
#include< conio.h>
void main()
{
int i,j,k;
char a[30],b[30];
clrscr();
puts("enter your name : \n");
gets(a);
printf("\n\nyour name in short is : \n\n%c",a[0]);
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
printf(".%c",a[i+1]);
}
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
for(j=i,k=0;a[j]!='\0';j++,k++)
b[k]=a[j];
}
b[k]='\0';
for(i=2;b[i]!='\0';i++)
printf("%c",b[i]);
getch();
}
This blog is for basic C programming language skills with interesting examples. It will help to the students who just started to learning C programming.
Tuesday, November 24, 2009
c program to abbreviate names
Subscribe to:
Post Comments (Atom)
thank u
ReplyDeleteThis comment has been removed by the author.
DeleteKya thank you output to check kar lo pahle
Deletethanx for to write this program
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis program is not fully correct because if you enter only single name like"ramesh"
ReplyDeletethen it will show garbage value like "ringh".
Soory sir i m not fully satisfied with the program can u plz b able to explain the second for loop in which we r incrementing from which value of i and one more thing i wanna clear from u . Do value of i persist between 1st nd 2nd for loop
ReplyDeleteSoory sir i m not fully satisfied with the program can u plz b able to explain the second for loop in which we r incrementing from which value of i and one more thing i wanna clear from u . Do value of i persist between 1st nd 2nd for loop
ReplyDeletedear shakeel, let me explain u from the begning..
ReplyDeletesay entered name is "Mohandas Karamchand Gandhi"
> first print statement prints the first character i.e M
> next for loop prints the first character after every space within the name with a preceding "." so we get M.K.G
> now the next for loop statement again check the spaces within the name and it stores the rest of the name with the space within another array i.e b
so first it will store " Karamchand Gandhi" in b
then it will store " Gandhi" in b
> then we are printing b array from the 3rd element (2nd position of array) as 1st and 2nd element is processed earlier.
so it will print "andhi"
finally M.K.Gandhi is printed as output.
hope it helps. :)
I cannot understand how that loop determines the last space of tha array. I think it will check spaces, & whenever it get spaces, such as after MOHANDAS, it will start printing KARAMCHAND. But we have to determine the last space & print the characters after that space.
DeleteCould I explain my doubt? If yes, please make me understand.
This comment has been removed by the author.
ReplyDeleteWhere is the Output?
ReplyDeleteTiyasha Bera
Delete