【发布时间】:2022-01-14 19:47:35
【问题描述】:
我正在编写一个函数,该函数将为用户提供从列表中选择项目的选项。 选择选项时,它应该调用专用函数来询问项目的数量,然后将其输出到文件。下面是两个函数。
void pos2()
{
int choice;
printf("\n Enter The item : ");
scanf("%d", &choice);
switch (choice) {
case 1:
apple();
break;
case 2:
editInventory();
break;
case 3:
printf("\n Returning... \n\n");
printf("Returning in 3 seconds...\n");
Sleep(3000);
system("cls");
printMenu();
default:
system("cls");
printf("\ninvalid choice Try again \n");
printMenu();
}
}
void apple()
{
FILE*out=fopen("pos.txt","w");
int amt;
printf("Apple Choosen\n");
printf("Enter the Amount\n");
scanf("%d",&amt);
fprintf(out,"%d",&amt);
}
在这种情况下,用户现在只能选择 1,这将要求他们输入苹果的数量,然后输入,它会将值保存到名为 pos.txt 的文本文件中。当我输入一个金额时,似乎我得到了地址值或某种数组作为回报。这是文本文件中的输出:
6421716
如果有人可以提供帮助或指导我正确的方向,我将不胜感激。提前致谢
【问题讨论】:
-
fprintf(out,"%d",&amt);删除&。你的编译器应该会警告你,查看如何打开所有警告。 -
很遗憾,我没有收到任何警告。我现在就这样做,非常感谢。