zoukankan      html  css  js  c++  java
  • C语言 · 空白格式化

    标题:空白格式化

    “空白格式化”具体做法是:去掉所有首尾空白;中间的多个空白替换为一个空格。所谓空白指的是:空格、制表符、回车符。

    填空为:*p_to<*p_from;

     1 #include<stdio.h>
     2 #include<string.h>
     3 void f(char* from, char* to){
     4     char* p_from = from;//定义字符指针
     5     char* p_to = to;
     6     while(*p_from==' ' || *p_from=='	' || *p_from=='
    ')
     7         p_from++;
     8     do{
     9         if(*p_from==' ' || *p_from=='	' || *p_from=='
    '){ 
    10             do{
    11                 p_from++;
    12             }while(*p_from==' ' || *p_from=='	' || *p_from=='
    ');
    13             if(*p_to<*p_from)
    14                 *p_to++ = ' ';
    15         }
    16     }while(*p_to++ = *p_from++);
    17 }
    18 int main(){
    19     char str[5000];
    20     gets(str);
    21     int len = strlen(str);
    22     f(str,str);
    23     printf("%s",str);
    24     return 0;
    25 }
  • 相关阅读:
    查看linux命令类型
    理解bashrc和profile[转载]
    问题:ldconfig
    箭头函数
    闭包函数
    方法
    手把手教你使用百度地图(图解)
    变量作用域与解构赋值
    iterable
    Map和Set
  • 原文地址:https://www.cnblogs.com/panweiwei/p/6682901.html
Copyright © 2011-2022 走看看