关于s++问题
求空格,大写,小写,数字各有几个#include<stdio.h>
#include<stdlib.h>
#define N 100
void main()
{
char*p=(char*)malloc(N*sizeof(char));
int num=0,space=0,up=0,low=0,other=0;
printf("input the string:");
gets(p);
for(;*p!='\0';p++)
{
if((*p>='0')&&(*p<='9'))
num++;
else if(*p==' ')
space++;
else if((*p>='A')&&(*p<='Z'))
up++;
else if((*p>='a')&&(*p<='z'))
low++;
else
other++;
}
printf("num=%d,space=%d,up=%d,low=%d,other=%d\n",num,space,up,low,other);
}
为什么char*p...不能换成p[N];
#include<stdio.h>
#include<stdlib.h>
#define N 100
void main()
{
char p[N];
int num=0,space=0,up=0,low=0,other=0;
printf("input the string:");
gets(p);
for(;*p!='\0';p++)
{
if((*p>='0')&&(*p<='9'))
num++;
else if(*p==' ')
space++;
else if((*p>='A')&&(*p<='Z'))
up++;
else if((*p>='a')&&(*p<='z'))
low++;
else
other++;
}
printf("num=%d,space=%d,up=%d,low=%d,other=%d\n",num,space,up,low,other);
}
错误: error C2105: '++' needs l-value