统计字符串中字符个数

怎么统计字符串中的字符个数,不包含空格换行符(初学者C++)


#include<stdio.h>

int main()
{
    char ch[150];
    scanf("%s",ch);
    int i=0;
    while(ch[i]!='\0')
    {

        // printf("%c\n",ch[i]);
        i++;

    }
    printf("\n%d\n",i);
    return 0;
}

#include <iostream>
#include <conio.h>

using namespace std;

#define MAXS 80

char* ReadString (char s[]) {
    gets (s);
    return s;
}

void StringCount (char s[]){
    char *p = s;
    int letter = 0;
    while (*p != '\0') {
        if (*p != ' ')
            letter++;
        p++;
    }
    cout<<"letter ="<<letter<<endl;
}

int main(void) {
    char s[MAXS];

    ReadString(s);
    StringCount(s);

    return 0;
}

运行结果:

img