title: How to convert a string (char *) to upper or lower case in C
body: <p>I have a struct:</p>
  
  <pre><code>typedef struct entry {
  char *surname;
  int house_no;
  char *postcode;
  } BEntry;
  </code></pre>
  
  <p>and a function to convert strings to upper case:</p>
  
  <pre><code>void toUpper(char *str){
      while (*str != '\0')
      {
          *str = toupper(*str);
          str++;
      }
  }
  </code></pre>
  
  <p>and in my main function I assign values to the struct members and want to convert the surname to upper case:</p>
  
  <pre><code>mentry-&gt;surname = "bob";
  mentry-&gt;house_no = 17;
  mentry-&gt;postcode = "GK116BY";
  toUpper(me-&gt;surname);
  </code></pre>
  
  <p>What is the correct way to convert a string to upper case by passing a char pointer to a function like this? My program is returning a segmentation fault. Any help is most appreciated, thanks.</p>