vc++ 去空格

vc++ 去空格,第1张

while(q)

{

if(*q!=' ')

*p++=*q

q++

}

这里改成

while(q &&*q!='\n')

{

if(*q!=' ')

*p++=*q

++q

}

*p = '\n'

main里面这样用

void main()

{

char test[]="1 2 3 45 6"

char *noblanks = Trim(test)

cout<<"after triming :"<<noblanks<<endl

}

#include <iostream>

using namespace std

void delspace(char* str)

{

for(char* p=str*p!='\0'p++){

if(*p!=' ')

*str++ = *p

}

*str = '\0'

}

int main(int argc, char *argv[])

{

char buf[100]

cout <<"请输入:"

cin.getline(buf,sizeof(buf))

delspace(buf)

cout <<buf <<endl

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9908845.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存