⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trim.c

📁 国外网站上的一些精典的C程序
💻 C
字号:
/***  TRIM.C - Remove leading, trailing, & excess embedded spaces****  public domain by Bob Stout & Michael Dehlwes*/#include <ctype.h>#include "snip_str.h"#if defined(__cplusplus) && __cplusplus extern "C" {#endifchar *trim (char *str){      char *ibuf, *obuf;      if (str)      {            for (ibuf = obuf = str; *ibuf; )            {                  while (*ibuf && (isspace (*ibuf)))                        ibuf++;                  if (*ibuf && (obuf != str))                        *(obuf++) = ' ';                  while (*ibuf && (!isspace (*ibuf)))                        *(obuf++) = *(ibuf++);            }            *obuf = NUL;      }      return (str);}#if defined(__cplusplus) && __cplusplus }#endif#ifdef TEST#include <stdio.h>#include <stdlib.h>int main (int argc, char *argv[]){      if (argc == 2)      {            printf ("trim(\"%s\")\n", argv[1]);            printf ("returned \"%s\"\n", trim (argv[1]));      }      else      {            fprintf (stderr, "To test this function, call TRIM\n");            fprintf (stderr, "with an argument enclosed in quotes.\n");            fprintf (stderr, "   Example:\n");            fprintf (stderr, "   C:\\>trim \"  test   test   \"\n");            fprintf (stderr, "   trim(\"  test   test   \"\n");            fprintf (stderr, "   returned \"test test\"\n\n");            fprintf (stderr, "   C:\\>_\n");            return EXIT_FAILURE;      }      return EXIT_SUCCESS;}#endif /* TEST */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -