首页 > 其他 > 详细

字符输入输出

时间:2019-11-07 18:14:30      阅读:82      评论:0      收藏:0      [点我收藏+]

 /************************************/

/*文件复制*/
#include <stdio.h>
main()
{
 int c;
 c = getchar();
 while(c != EOF)
 {
  putchar(c);
  c = getchar();
 }
}
 
/*********************************/
/*字符计数*/
#include <stdio.h>
main()
{
 double nc;
 for(nc=0;getchar()!=EOF;++nc)
  ;
 printf("%.0f\n",nc);
}
 
/***********************************/
/*行计数*/
#include <stdio.h>
main()
{
 int c,n1;
 n1 = 0;
 while((c=getchar())!= EOF)
  if(c == ‘\n‘)
   ++n1;
 printf("%d\n",n1); 
}
 
/*****************************************/
/*单词计数*/
#include <stdio.h>
#define IN 1 /*在单词内*/
#define OUT 0 /*在单词外*/
/*统计输入的nl行数、nc单词数与nw字符数*/
main()
{
 int c,n1,nw,nc,state;
 state = OUT;
 n1 = nw =nc = 0;
 while((c = getchar()) != EOF)
 {
  ++nc;
  if(c == ‘\n‘)
   ++n1;
  if(c == ‘ ‘ ||c = ‘\n‘ c == ‘\t‘)
   state = OUT;
  else if (STATE == OUT)
  {
   state = IN;
   ++nw;
  }
 }
 printf("%d %d %d\n",n1,nw,nc);
}
 
 
 
 
 
 
 
 
 

字符输入输出

原文:https://www.cnblogs.com/TheFly/p/11813929.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!