--- In c-prog@yahoogroups.com, "py2akv" <g...@...> wrote:
>
> John,
> 
> Very good

Thanks!

> but you worked with an array of char's & a pointer to char's: two strings & 
> one a copy of the other, a sort of a crutch, he, he, he.

Eh? That's just one string (str) and one pointer to char (s). I could always 
rewrite

   const char str[] = "string";

as:

   const char *const str = "string";

but then you have an anonymous array of chars ("string") AND a pointer to char 
(str).

> Came to a different solution using only the original string & the 
> fundamentals of the language.

With better layout:

> char *s="    C    Programming    Language    ";

Should be const char *

> int f1=1, f2=1;
> 
> while (*s) {
>   if (*s!=' ') {
>     if (f1)
>       printf("%c", *s);
>     f1=0;

Mistake - the f1=0 should be conditional on the if?
(more obvious when code is laid out correctly)

>   }
>   else if (!f1) {
>     printf("%c", *s);
>     f2=0;
>   }
>   if (!f1 & !f2)
>     f1=f2=1;
>   ++s;
> }

My code was 3 lines; yours is 11 (not counting brace-only lines). Do you get 
paid by the line? :-)

> >   for (n = 0, s = str; *s; s++)
> >       if ((*s != ' ') && ((s == str) || (s[-1] == ' ')))
> >           printf(" %c" + !n++, *s);

> The backspace at the end is optional,

Sorry - don't understand what you mean by this.

Reply via email to