<pre><code>/*
 * This can be  used with Geany's custom commands
 *  it will capitalize the first letter in a selection, and every following word that
 * is preceded by a space.
 */

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

#define MAX_LENGTH 1024

int main(int argc, char **argv)
{
  char *selection = malloc (sizeof (char* ) * MAX_LENGTH + 1);

  if (fgets (selection, MAX_LENGTH + 1, stdin) != NULL)
  {
    if (strlen (selection) > MAX_LENGTH)
      return 1;

    int pos = 0;

    while (selection[pos] != '\0')
    {
      if (selection[pos] == ' ' || pos == 0)
      {
        /* Use a loop here in case a space follows a space in the string
         * otherwise the second ' ' would get capped, but not the letter
         * that follows it
         *
         * NOTE: Most people would probably just want the extra space
         * deleted but left as is for now)
         */
        while (selection[pos] == ' ')
          pos++;

        selection[pos] = toupper (selection[pos]);
      }
      pos++;
    }

    fprintf (stdout, "%s", selection);
    return 0;
  }

  return 1;
}

</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany/issues/1037#issuecomment-255227671">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABDrJ-6LQfzzOxi327fxtMO8TEcXETFbks5q19c-gaJpZM4IejnE">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABDrJwNWQ4H6ZxEyNWrfmrtfGfblewS1ks5q19c-gaJpZM4IejnE.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany/issues/1037#issuecomment-255227671"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/geany/geany","title":"geany/geany","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/geany/geany"}},"updates":{"snippets":[{"icon":"PERSON","message":"@andy5995 in #1037: ```\r\n/*\r\n * This can be  used with Geany's custom commands\r\n *  it will capitalize the first letter in a selection, and every following word that\r\n * is preceded by a space.\r\n */\r\n\r\n#include \u003cstdio.h\u003e\r\n#include \u003cctype.h\u003e\r\n#include \u003cstring.h\u003e\r\n#include \u003cstdlib.h\u003e\r\n\r\n#define MAX_LENGTH 1024\r\n\r\nint main(int argc, char **argv)\r\n{\r\n  char *selection = malloc (sizeof (char* ) * MAX_LENGTH + 1);\r\n\r\n  if (fgets (selection, MAX_LENGTH + 1, stdin) != NULL)\r\n  {\r\n    if (strlen (selection) \u003e MAX_LENGTH)\r\n      return 1;\r\n\r\n    int pos = 0;\r\n\r\n    while (selection[pos] != '\\0')\r\n    {\r\n      if (selection[pos] == ' ' || pos == 0)\r\n      {\r\n        /* Use a loop here in case a space follows a space in the string\r\n         * otherwise the second ' ' would get capped, but not the letter\r\n         * that follows it\r\n         *\r\n         * NOTE: Most people would probably just want the extra space\r\n         * deleted but left as is for now)\r\n         */\r\n        while (selection[pos] == ' ')\r\n          pos++;\r\n\r\n        selection[pos] = toupper (selection[pos]);\r\n      }\r\n      pos++;\r\n    }\r\n\r\n    fprintf (stdout, \"%s\", selection);\r\n    return 0;\r\n  }\r\n\r\n  return 1;\r\n}\r\n\r\n```"}],"action":{"name":"View Issue","url":"https://github.com/geany/geany/issues/1037#issuecomment-255227671"}}}</script>