title: lower case string in c
body: <p><strong>i had a few line here :</strong> </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  char *tolower(char *data)
  {
      char *p = data;
      while(*p)
      {
          printf("nilai p : %c\n",*p);
              if(*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z')
              {
                  *p += ('a' - 'A');
              }
          p++;
      }
      return p;
  
  }
  
  int main()
  {
  
      char *a = "HajAR BleH";
      char *b = tolower(a);
  
      printf("nilai b : %s\n",b);
      printf("nilai a - A : %d\n",'a' - 'A');
  return 0;
  }
  </code></pre>
  
  <p><strong>next, compiled, running on gdb, and segmentation traced</strong></p>
  
  <pre><code>xxx@aaa:/tmp$ gcc -o aa aa.c --debug
  xxx@aaa:/tmp$ gdb -q aa
  Reading symbols from /tmp/aa...done.
  (gdb) r
  Starting program: /tmp/aa 
  nilai p : H
  
  Program received signal SIGSEGV, Segmentation fault.
  0x0804841e in tolower (data=0x804855e "HajAR BleH") at aa.c:11
  11                  *p += ('a' - 'A');
  (gdb) 
  </code></pre>
  
  <p><strong>question</strong> </p>
  
  <p><strong>1.</strong> i think <code>*p += ('a' - 'A');</code> will equal as <code>'H' += ('a' - 'A')</code> and equal with <code>72 += 32</code>
  but, accidentally segmentation fault, how come it could be ?</p>
  
  <p><strong>2.</strong> why need to add ('a' - 'A') to make <code>char</code>/<code>byte</code> get lower ?</p>
  
  <p>thats all for now, thank in advance </p>