开发者

EOF function in c++ |c

for example there is code

#include <algorithm>
#include <stdio.h>
#include <iostr开发者_运维知识库eam>



int intcomp(int *x,int *y) {  return *x-*y;};
int a[10000];
int main(void){
    int i; int n=0;
     while (scanf("%d",&a[n])!=EOF)
          n++;
     qsort(a,n,sizeof(int),intcomp);
      for (int i=0;i<n;i++)
           printf("%d\n",a[i]);
       return 0;


}

how tell computer that EOF is reached?


You mean when entering input interactively? In a windows shell, ctrl+z on a line on its own. In a *nix shell, ctrl+d. Or just put your input in a file and pipe it, then not only will eof be detected at the appropriate time but also you can automate your testing.


You should use CTRL+Z combination (or somehow input character with code 26, for example, by pressing ALT+2+6 on additional keyboard)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜