c字符数组之两头堵模型

  • char *其实就是char[length]的首元素地址  实验环境:centos7下qt5.11 中文char类型占3个字节
char[length]="特别车队"其实等价于char *mywords="特别车队"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
    char * words="    特别车队狮哥候警官老狒";
    int i,j=0;
    j=strlen(words)-1;
    while(isspace(words[i]) && words[i]!='\0')
    {
        i++;
    }
    while(isspace(words[j]) && words[j]!='\0')
    {
        j--;
    }
    int n=j-i;

    printf("%d\n",n);
    while(i<=j){
        printf("%c",words[i]);
        i++;
    }
    printf("\n%s\n",words);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/saintdingspage/p/12048563.html