故意不挂车牌怎么处罚:把字符串开头的空格去掉,用指针。

来源:百度文库 编辑:高考问答 时间:2024/04/28 08:30:59
c语言!
多谢!
尽快

#include<stdio.h>
main()
{
int i=0;
char *p;
char str[]=" you are a pig";
p=str;
while(*p==' ')
p++;
while(*p!='\0')
str[i++]=*(p++);
str[i]='\0';
printf("%s",str);
}

void ltrim(char * src,char *dst)
{
char *ptr=src;
int start=1;
while(*ptr!='\0'){
if(*ptr!=' '){
start=0;
}

if(start&&*ptr==' '){
ptr++;
continue;
}
*dst=*src;
ptr++;
dst++;

}
*dst='\0';
}