Uday,

With respect to others who already gave you good ideas, I'd like to show you my 
modest contribution.

The string below is the worst case scenario with blanks at the beginning, at 
the middle and at the end, but the program works equally well with blanks at 
the sides only, at the middle, or any combination you like, even with no blanks 
at all.

This outputs "C P L", nicer for the purists, not "C P L " (with an extra blank 
at the end) which requires less attention.

char *str = "    C    Programming    Language    ";
int f=0;

while (*str) {
if (*str!=' ') 
{printf(f ? " %c" : "%c", *str); f=1; while (*str && *++str!=' ');}
else
while (*++str==' ');
}

This outputs "C P L ".

char *str = "    C    Programming    Language    ";

while (*str) {
if (*str!=' ') 
{printf("%c ", *str); while (*str && *++str!=' ');}
else
while (*++str==' ');
}

This is the same as the code above, but outputs "C P L" with the help of a 
little trick: printf("\b")/printf("%c", '\b').

char *str = "    C    Programming    Language    ";

while (*str) {
if (*str!=' ') 
{printf("%c ", *str); while (*str && *++str!=' ');}
else
while (*++str==' ');
}
printf("\b");

Best,

Geraldo


--- In c-prog@yahoogroups.com, Uday Oberio <uday_obe...@...> wrote:
>
> hello everyone
>  
> In C programming i want to solve one programm of string that is
> Enter String is  C Programming Language 
> Output is C P L.
> means output is first letter of every word.how it can be possible .. please 
> help me 
> thanking you
> with regards
> Uday
>  
> 
> 
>       The INTERNET now has a personality. YOURS! See your Yahoo! Homepage. 
> http://in.yahoo.com/
> 
> [Non-text portions of this message have been removed]
>


Reply via email to