用指针实现从键盘输入一串字符,以字符’#’,作为结束标志。
#include#include#include int main(){ char ch; char str[100]; char *p; int i=0; int num=0; printf("please input a string:\n"); ch=getch(); //while((ch=getch())!='#') do { printf("%c",ch); str[i]=ch; i++; //ch=getchar(); }while((ch=getch())!='#'); printf("%c",ch); str[i]='\0'; p=str; for(p;*p!='\0';p++) { if(*p==' ') { num++; } } num++; printf("\nthere are %d words in string\n",num); return 0;}