【发布时间】:2021-07-18 14:01:01
【问题描述】:
当我调用显示函数时,它不会在程序中调用,当我在主函数中使用它而不在函数中使用它时,它可以正常工作。
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int d;
int choose;
int display();
printf("enter 1 to display and 2 to quit\n");
switch(choose)
{
case 1:
display();
break;
}
scanf("%s",choose);
int display();
system("cls");
}
int display()
{
char fname[20], str[500];
FILE *fp;
printf("Enter the Name of File: ");
gets(fname);
fp = fopen(fname, "r");
if(fp==NULL)
printf("Error Occurred while Opening the File!");
else
{
fscanf(fp, "%[^\0]", str);
printf("\nContent of File is:\n\n");
printf("%s", str);
}
fclose(fp);
getch();
return 0;
}
知道错误是什么吗?
【问题讨论】:
-
@avm 下面说了什么。此外,您不会在 switch 语句之后指定要选择的值,这样代码就永远不会被执行。
-
你的文字很难理解。请考虑编辑
标签: c function file dev-c++ txt