去掉前后空格,返回一个新字符串,C

#include<stdio.h>

int trimSpace(char *inbuf, char *outbuf)
{
    int ret = 0;
    if (inbuf == NULL || outbuf == NULL)
    {
        ret = -1;
        return ret;
    }

    char * intail = inbuf;
    while (*intail!=‘\0‘)
    {
        intail++;
    }
    intail--;
    while (*intail==‘ ‘)
    {
        *intail = ‘\0‘;
        intail--;
    }
    while (*inbuf == ‘ ‘)
    {
        inbuf++;
    }
    while (*inbuf!=‘\0‘)
    {
        *outbuf++ = *inbuf++;
    }
    *outbuf = ‘\0‘;

    return ret;
}

int main()
{
    char buf[] = "      abhf dsiu    qwe                aaaaaaaaaa                        ";
    char out[50];
    int ret;
    ret = trimSpace(buf, out);
    if (ret == 0)
    {
        printf("%s.", out);
    }
    else
    {
        printf("err:%d", ret);
        return ret;
    }

    return 0;
}
时间: 2024-07-31 22:04:24

去掉前后空格,返回一个新字符串,C的相关文章

Python3基础 字符串 capitalize 返回一个新的字符串,它的第一个字母大写

镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.------------------------------------------ code: myStr='hello world' myNewStr=myStr.capitalize() #返回一个新的字符串 print(myStr) # 原字符串并未改变 print(myNewStr) result: ============= RESTART: C:/Users/

python中将指定的字符串转换为大写字母并每隔2个字符用空格分割后得到一个新字符串的方法

在例子中对指定的字符串: faa5fbb5fcc5fdd5010200000028000001900000000a002d00000000017d7840000003e800005fa55fb55fc55fd5 使用了三种方法将其转换为大写字母并每隔2个字符用空格分割处理后得到一个新字符串,为: FA A5 FB B5 FC C5 FD D5 01 02 00 00 00 28 00 00 01 90 00 00 00 0A 00 2D 00 00 00 00 01 7D 78 40 00 00

04微信公众平台 - 实现【翻译】功能函数,返回一个文本字符串。

一.功能代码函数实现 private function _baiduDic($keyword) { $tranurlaip = "http://openapi.baidu.com/public/2.0/bmt/translate?client_id=9peNkh97N6B9GGj9zBke9tGQ&q={$keyword}&from=auto&to=auto"; //翻译URLapi地址 $transtr = file_get_contents($tranurl

05微信公众平台 - 实现【点歌】功能函数,返回一个文本字符串。

一.功能代码函数实现 /* * 功能5:根据歌名点歌功能,输入歌名即可,传入参数为输入对象$postObj */ private function _listenMusic($postObj) { $ret= "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTi

03微信公众平台 - 实现【天气查询】功能函数,返回一个文本字符串。

一.功能代码函数实现 private function _weather($city) { include("weather_cityId.php"); $c_name=$weather_cityId[$city]; if(!empty($c_name)){ $json=file_get_contents("http://m.weather.com.cn/data/".$c_name.".html"); $data = json_decode($

给定两个非空链表来表示两个非负整数。位数按照逆序方式存储,它们的每个节点只存储单个数字。将两数相加返回一个新的链表。

题目描述: 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 思路: 1.定义链表类 2.创建两个数的链表表示对象 3.传入函数实现相加:每一位相加,设置进位,移到下一位,直到待加链表都为空 具体代码: 1 public class ListNode { 2 int val; 3 ListNode next; 4 5 ListNode(int x) { 6 val = x; 7 } 8 9 } 10 11 public class lkk { 12 public ListNode add

给定一个字符串 S 和一个字符 C。返回一个代表字符串 S 中每个字符到字符串 S 中的字符 C 的最短距离的数组。

def shortestToChar(S, C): c=[] s=[] for i,v in enumerate(S): if v==C: c.append(i) for i,v in enumerate(S): m=[] for j in c: m.append(abs(i-j)) s.append(min(m)) return s 原文地址:https://www.cnblogs.com/zhangtianxia/p/9043620.html

Python3基础 str capitalize 返回新字符串,第一个字母大写

? python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 conda : 4.5.11 type setting : Markdown ? code [email protected]:~$ source activate py37 (py37) [email protected]:~$ ipython Python 3.7.0 (default, Jun 28 2018, 13:15:42) Type 'copyright'

#每天学习一个新的php函数 (1) substr()

最近发现自己的写代码的效率太低了.查找原因,发现大部分的时间都用来去查找手册找函数的用法去了,但是找当时用过后就马上忘掉了,第二次遇到这个函数还是的重新来过.浪费了大量的时间.所以决定写一个小结的集合,争取把每天遇到的最频繁的那个函数记载下来. string substr ( string $string , int $start [, int $length ] ) 该函数用来截取指定字符串,功能很强大. param $start 如果 start 是非负数,返回的字符串将从 string 的