/* Program to illustrate the storage and manipulation of strings in C */

#include <stdio.h>
#include <string.h>

int main (void) {
  char s[10] = "abcdefghi";
  char * a;
  char * b;
  char c[10];
  char * d;
  char e[25] = "0123456789";
  char * f;
  char * four_in_e;
  char * e_in_e; 
  char * X_in_e;

  /* initialization */
  a = s;
  b = a;
  strcpy (c, "uvwxyz");  /* copy "uvwxyz" to c */
  d = c;
  f = strcat (e, s);     /* concatenate e with s, giving e [and f] as result */

  /* print initial values */
  printf ("Initial values of variables\n");
  printf ("   s:  %s\n", s);
  printf ("   a:  %s\n", a);
  printf ("   b:  %s\n", b);
  printf ("   c:  %s\n", c);
  printf ("   d:  %s\n", d);
  printf ("   e:  %s\n", e);
  printf ("   f:  %s\n", f);

  /* modify positions in various string variables */
  s[3] = 'm';
  a[5] = 'p';
  b[7] = 'r';
  c[1] = 'k';
  d[3] = 'q';
  e[9] = 'N';
  f[8] = 'Z';

  /* print after modifications */
  printf ("Values of variables after various strings changed\n");
  printf ("   s:  %s\n", s);
  printf ("   a:  %s\n", a);
  printf ("   b:  %s\n", b);
  printf ("   c:  %s\n", c);
  printf ("   d:  %s\n", d);
  printf ("   e:  %s\n", e);
  printf ("   f:  %s\n", f);

  /* perform some searching */
  four_in_e = strstr(e, "4");
  e_in_e = strstr(e, e);
  X_in_e= strstr(e, "X");; 

  /* print result of searches */
  printf ("Searching results\n");
  printf ("   Base address of string e is %u\n", (unsigned) e);
  printf ("   Index of '4' in e is %u\n", (unsigned)four_in_e);
  printf ("   Index of e in e is %u\n", (unsigned)e_in_e);
  printf ("   Index of 'X' in e is %u\n", (unsigned)X_in_e);
  return 0;
}
