Read a string from user using gets() function. Now travel the whole string and pick out the first character of every word and convert it into upper case and concat a '.' character. Now pick out the last word an concat it to the result.
int main()
{
char str[30],res[30],i,w,k=0;
//READ A STRING
printf("Enter A String: ");
gets(str);
for(i=0;str[i]!='\0';i++)
{
if((str[i]>=65 && str[i]<=90) ||(str[i]>=97 && str[i]<=122))
{
if(i==0 ||str[i-1]==' ')
{
w=i+1;
if(str[i]>=97 && str[i]<=122)
{
str[i]=str[i]-32;
}
res[k++]=str[i];
res[k++]='.';
}
}
}
k--;
for(i=w;str[i]!='\0';i++)
{
if(str[i]>=65 && str[i]<=90)
{
res[k++]=str[i]+32;
}
else
{
res[k++]=str[i];
}
}
res[k++]='.';
res[k]='\0';
//PRINT THE OUTPUT
printf("Result : ");
puts(res);
return 0;
}
Enter A String: rabinDra natH tagore
Result : R.N.Tagore.