为什么命令提示符在我开始之前显示数字?

Why does command prompt show numbers before I begin?

命令提示符在程序开始前显示数字。为什么? 2687688 给出 但数字不会写入文件?

#include <stdio.h>
#include <conio.h>

int main(void){
    FILE*nfPtr;
    int n;
    if ((nfPtr=fopen("c:\Users\raphaeljones\Desktop\newfile.dat","w"))==NULL)
{
    printf ("Sorry! The file cannot be opened\n");
}
    else
{//else 1 begin

    printf("Enter numbers to be stored in file\n");
    printf("%d",&n);
    while (!feof(stdin)){
          fprintf(nfPtr,"%d",n);
          scanf("%d",&n);
          }
}//else 1 ends
        fclose(nfPtr);

getch();
return 0;
}

除了其他问题,在你的代码中

 printf("%d",&n);

绝对错误并调用 undefined behaviour。 .也许你的意思是

 scanf("%d",&n);

扫入号码。

也就是说,请看,why you should refrain from using !feof(file)

替补

printf("%d",&n);

scanf("%d",&n);

printf Writes the C string pointed by format to the standard output (stdout)

scanf Reads data from stdin

在你的代码中你正在打印 n,它没有被初始化,在 "Enter numbers to be stored in file" 字符串之后打印出一个随机数。