zoukankan      html  css  js  c++  java
  • 当函数发现字符串中如果有一个地方由一个或多个连续的空格组成,就把它们改成单个空格字符。

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 void deblank(char str[]);
     5 int main()
     6 {
     7     char str[100] ;
     8     memset(str,0,100);
     9     printf("please input the string str:");
    10     gets(str);
    11     deblank(str);
    12     puts(str);
    13     system("pause");
    14     return 0;
    15 }
    16 void deblank(char str[])
    17 {
    18     int i = 0;
    19     int j = 0;
    20     while(str[i] != ''&& str[i+1] != '')
    21     {
    22         if(str[i] != ' ' || (str[i] == ' ' && str[i+1] != ' '))
    23         {
    24            str[j] = str[i];
    25             j++;
    26             i++;
    27         }
    28         else
    29             {
    30                 i++;
    31         }
    32     }
    33     str[j+1] = '';
    34 }
  • 相关阅读:
    用户交互语句
    基础数据类型补充与总结
    Python 中表示 False 的方法
    集合
    字典
    元组
    列表
    整型数据详述和进制转换
    f-strings 详解
    字符串方法详解
  • 原文地址:https://www.cnblogs.com/joyclub/p/4480305.html
Copyright © 2011-2022 走看看