How to make a file, i try to make a file.txt in c but i got an error, the program where i write successed execute but in file or in notepad the contents do not exist.
Code:
this my snippet of my code what I want to input to file.txt:
int a,b,c,d,e = 0,f = 0;
int check,check2,check3;
int *fptr;
fptr = fopen("file.txt","w");
printf("\nenter the amount of food to be purchased : ");
check=scanf("%d", &b);
printf("\n");
if (check != 0) {
for (a=1; a<=b; a++){
printf("the price of food of- %d \t : ",a);
check2=scanf("%d", &c);
printf("\n");
if (check2==0) {
printf("Please enter in numeric !!\n");
while ((getchar()) != '\n');
system("PAUSE");
goto cashier;
}
printf("the amount ordered \t : ");
check3=scanf("%d", &d);
printf("\n");
if (check3==0) {
printf("Please enter in numeric !!\n");
while ((getchar()) != '\n');
system("PAUSE");
goto cashier;
}
e=c*d;
f+=e;
}
printf("total price of food \t : Rp.%d",f);
printf("\n");
char isTrue;
printf("\n\nPush [Y] to save a copy from your payment [T]\nTo Out\n:");
scanf(" %c",&isTrue);
if(isTrue == 'y' || isTrue == 'Y'){
fprintf(fptr, "the food you buy as much : %d\n", b);
fprintf(fptr, "total price of food : %d\n", f);
fclose(fptr);
goto cashier;
}
what should i do to fix this program ?
i want this fprintf(fptr, "the food you buy as much : %d\n", b);will execute and print it : "write the food you buy as much" in my notepad. but in my notepad file.txt i do not write anything before and also i do not create this file.txt name before