c语言的不懂

不爱吃酸的大力水手 2012-11-28 03:50:27
#include<stdio.h>
#define OUT 0
#define IN 1
int main()
{
int c,state;
state = OUT;
while ((c = getchar()) != EOF) {
if (c == ' ' || c == '\t' || c == '\n') {
if (state == IN) {
putchar('\n');
state = OUT;
}
} else if (state == OUT) {
putchar(c);
state = IN;
}else
putchar(c);
}
}
这个程序的每一步是什么意思??
#include <stdio.h>
#define IN 1
#define OUT 0

int main()
{
int c,nl,nw,nc,state;

state=OUT;
nl=nw=nc=0;
while((c=getchar())!=EOF){
++nc;
if(c=='\n')
++nl;
if(c==' '||c=='\n'||c=='\t')
state=OUT;
else if(state==OUT){
state=IN;
++nw;
}
}
printf("%d %d %d\n",nl,nw,nc);
system("pause");
}
这两个有什么区别,还有那些++nc等代码是什么意思??
...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
没办法,刚学的
14号选手 2012-11-28
  • 打赏
  • 举报
回复
单步调试你就知道每一步的作用了
tingfengx 2012-11-28
  • 打赏
  • 举报
回复
引用 1 楼 jbr5740 的回复:
第一个问题是指第一个程序而言的
++是运算符,楼主基本功不行啊
tingfengx 2012-11-28
  • 打赏
  • 举报
回复
#include<stdio.h>
#define OUT 0
#define IN  1
int main()
{
 int c,state;//定义两个变量
 state = OUT;//state赋值为0
 while ((c = getchar()) != EOF) {         //输入字符     
  if (c == ' ' || c == '\t' || c == '\n') {  
   if (state == IN) {                     //如果state等于1,但不是,因为一开始赋值为0
    putchar('\n');                        //换行
    state = OUT;                          //将0赋给state   
   }
  } else if (state == OUT) {              //如果state等于1
   putchar(c);                            //输出while输入的字符
   state = IN;                            //state赋值为1
  }else
   putchar(c);
 }
}
  • 打赏
  • 举报
回复
第一个问题是指第一个程序而言的

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧