The command prompt shows numbers before program begins. Why? 2687688
is given
but the numbers won't write to file?
#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;
}
Substitute
with
In your code you are printing n, that is not initialized, that a random number is printed out after
"Enter numbers to be stored in file"
string.