为什么提示没有初始化? 求大神
程序代码:
#include <stdio.h> #include <string.h> void main() { int i=0,sum=0; char ch; char *str; ch=getchar(); *str=ch; while(ch!='\n') { *(str+i)=ch; i++; ch=getchar(); } *(str+i)='\0'; printf("str=%s\n",str); printf("Over!\n"); i=0; while((*str+i)!='\0') { if(*(str+i)==' ') {sum++; i++;} printf("sum=%d\n",sum); } getchar(); }
warning C4700: local variable 'str' used without having been initialized