第十六周项目二(5):去除开头的空格

来源:互联网 发布:光环大数据贴吧 编辑:程序博客网 时间:2024/05/17 08:28
#include <iostream>using namespace std;char *ptrim(char *str);int main(){    char s1[50]=" Hello world. ";    char s2[50]=" Good morning. ";    char s3[50]=" vegetable bird! ";    cout<<s1<<*ptrim(s1)<<endl;    cout<<s2<<*ptrim(s2)<<endl;    cout<<s3<<*ptrim(s3)<<endl;    return 0;}char *ptrim(char *str){    int i=1,j=0;    while (*(str+i+1)!='\0')    {            *(str+(j++))=*(str+(i++));    }    *(str+j)='\0';    return str+i;}

0 0
原创粉丝点击