16週目アイテム2-ポインタで文字列を回転-(5)文字列の前のスペースを除去


</pre><pre name="code" class="cpp">/*
 *Copyright (c)2014,              
 *All rights reserved.
 *    :C++.cpp
 *      :   
 *    :2014 12 14 
 *     :v1.0
 *
 *    :           
 *    :
 *    :         
 */
#include <iostream>
#include <cstdio>
using namespace std;
void ptrim(char *str);
int main(void)
{
     char s[100];
    cout<<"       :";
    gets(s);
    cout<<"   :\""<<s<<"\""<<endl;
    ptrim(s);
    cout<<"        :\"";
    cout<<s<<"\""<<endl;
    return 0;
}

void ptrim(char *str)
{
    char *p=str,*q=str;
    while(*q==' ')
        q++;
    while(*q!='\0')
        *p++=*q++;
    *p='\0';
    return;
}

実行結果: