编写一个函数。其参数为一个字符串,函数删除字符串中的空格

来源:互联网 发布:ubuntu 常用软件 编辑:程序博客网 时间:2024/06/06 05:15
/**编写一个函数。其参数为一个字符串,函数删除字符串中的空格**/#include<stdio.h>#include <string.h>#include<stdlib.h>#include <ctype.h>char *DeleteBlank(char *str,int len)    {      char *mPtr = NULL;      int i,j=0;      mPtr = (char *)malloc(sizeof(char)*len+1);      for (i=0;i<len;i++)      {          /****应用了字符函数isspace()****/        if (isspace (str[i]))            continue;        else            {            mPtr[j]=str[i];            ++j;            }         }      mPtr[j]='\0';      return mPtr;    }int main(void)   {   char *str = "hello wrold welcome to you.";   int len = strlen (str);   char *var = NULL;   printf ("str = %d\n",len);   var = DeleteBlank(str,len);   printf ("%s\n",var);    system("pause");    return 0;   }
1 0