请问,对于memcpy(buf1,buf2,10)的内容如何去掉buf1的前后空格

请教,对于memcpy(buf1,buf2,10)的内容怎么去掉buf1的前后空格?
请教,
1、对于memcpy(buf1,buf2,10)的内容怎么去掉buf1的前后空格?
2、对于buf1,去掉空格后怎么转换成int型?此时buf1的内容一定是整型数值,不用考虑是否不是整型
3、怎样判断buf1去掉前后空格后,buf1的内容是否以'ABC'开头,比如 'ABC123' 或者'ABCS9'等
谢谢

------解决方案--------------------
#include <string.h>
#include <ctype.h>
char *trim(char *str)
{
        char *p = str;
        char *p1;
        if(p)
        {
                p1 = p + strlen(str) - 1;
                while(*p && isspace(*p)) p++;
                while(p1 > p && isspace(*p1)) *p1-- = '\0';
        }
        return p;
}

调用:trim(buf1)
------解决方案--------------------
1、对于memcpy(buf1,buf2,10)的内容怎么去掉buf1的前后空格?
最简单的:buf1[10]=0;

2、对于buf1,去掉空格后怎么转换成int型?此时buf1的内容一定是整型数值,不用考虑是否不是整型
使用函数 atoi/atof等

3、怎样判断buf1去掉前后空格后,buf1的内容是否以'ABC'开头,比如 'ABC123' 或者'ABCS9'等
使用strstr函数

------解决方案--------------------
boost::trim(str);
------解决方案--------------------
引用:
Quote: 引用:

楼主到底要干吗,是不是就想把 buf1 转换成数字?

buf1的内容会不同,不同的地址COPy过来的,可以实现知道肯定是数字等,如果事先知道是数字,就转成int

try this.

#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <iostream>

int main ()
{
 auto const buf = "will be skipped.123456789.it does not matter";
 auto const len = std::strlen(buf)+1;

 // look for first character that is a digital character.
 auto const found = std::find_if(buf,buf+len,::isdigit);
 if (buf+len != found)
 {
  // if found, convert the following into a number,
  // taking as many characters as possible 
  // without invalidating a number's construct.
  std::cout << std::atoi(found) << std::endl;
 }
}

------解决方案--------------------
引用:
Quote: 引用:

1、对于memcpy(buf1,buf2,10)的内容怎么去掉buf1的前后空格?
最简单的:buf1[10]=0;

2、对于buf1,去掉空格后怎么转换成int型?此时buf1的内容一定是整型数值,不用考虑是否不是整型
使用函数 atoi/atof等

3、怎样判断buf1去掉前后空格后,buf1的内容是否以'ABC'开头,比如 'ABC123' 或者'ABCS9'等
使用strstr函数

buf1是个指针啊


指针和数组本质是一样,在大部分场合可以互用
------解决方案--------------------
不会用sscanf吗?
#include <stdio.h>
char s[]="123 ab 4";
char *p;
int v,n,k;
void main() {
    p=s;
    while (1) {
        k=sscanf(p,"%d%n",&v,&n);
        printf("k,v,n=%d,%d,%d\n",k,v,n);
        if (1==k) {
            p+=n;
        } else if (0==k) {
            printf("skip char[%c]\n",p[0]);
            p++;
        } else {//EOF==k
            break;
        }
    }
    printf("End.\n");
}
//k,v,n=1,123,3
//k,v,n=0,123,3
//skip char[ ]
//k,v,n=0,123,3
//skip char[a]
//k,v,n=0,123,3
//skip char[b]
//k,v,n=1,4,2
//k,v,n=-1,4,2
//End.

------解决方案--------------------
引用:
不会用sscanf吗?
#include <stdio.h>
char s[]="123 ab 4";
char *p;
int v,n,k;
void main() {
    p=s;
    while (1) {