Character input and output

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

/*文件复制*/
#include <stdio.h>
main()
{
 int c;
 c = getchar();
 while(c != EOF)
 {
  putchar(c);
  c = getchar();
 }
}
 
/*********************************/
/ * Character count * /
#include <stdio.h>
main ()
{
 Double NC;
 for (NC = 0; getchar () = the EOF;! ++ NC)
  ;
 the 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);
}
 
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/TheFly/p/11813929.html