/*
 * retezce II. (zpracovani retezce)
 */

#include <stdio.h>
#define pocet 256
char s[pocet], *p, *p1, *p2;

int main(void) {
  printf("\nZadej retezec: ");
  fgets(s,pocet,stdin);
  printf("Nacteny retezec   . . . . . . . s = '%s'\n",s);

  printf("Pocitam delku retezce . . . . . ");
  p=s; while( *p!='\0') p++;
  printf("pocet znaku (vcetne znaku EOLN) = %d\n", p-s);

  printf("Mazu EOLN z konce retezce . . . ");
  if (*(p-1)=='\n') {--p; *p='\0';}            // nebo strucneji: *--p='\0';
  printf("s = '%s'\n",s);

  printf("Hledam mezeru zleva   . . . . . ");
  p1=s; while( *p1 != '\0' && *p1 != ' ' ) p1++;
  if (*p1==' ') printf("mezera je na %d. pozici \n", p1-s + 1);
           else printf("mezera v retezci neni\n");

  printf("Hledam mezeru zprava  . . . . . ");
  p2=p; while( p2 > s && *p2 != ' ' ) p2--;
  if (*p2==' ') printf("mezera je na %d. pozici \n", p2-s + 1);
           else printf("mezera v retezci neni\n");

  if (*p1==' ') { 
    printf("Mazu znaky mezi mezerami  . . . ");
    while(*p2!='\0') *p1++ = *p2++; 
    *p1='\0'; 
    printf("s = '%s'\n",s);
  }

  printf("\n");
  return 0;
}