【发布时间】:2020-06-07 04:08:39
【问题描述】:
编程新手,实际上是在学习 C 的开放课堂教程,我发现自己被困在包括外部标题部分在内的内容上。我使用 IDE,我在 Visual Studio Code 上,我可以切换到 IDE,但在简单的文本编辑器中应该是可能的并且不难做到,所以我想了解如何。
程序运行时的错误代码:
main.c:6:10: fatal error: 'level.h' file not found
#include "level.h"
^~~~~~~~~
1 error generated.
这是我的main.c 代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>
#include "level.h"
#include "menu.h"
int level();
int menu();
int main()
{
int nombreMystere, guess, round = 10;
char answer;
bool exit = true;
while (exit)
{
menu();
{
while(guess != nombreMystere)
{
printf("%d" , nombreMystere);
printf("\nIl vous restes %d round.\n", round );
printf("Trouver le nombre magique: " );
scanf ("%d" , &guess );
if(guess < nombreMystere) printf("Trop bas\n");
else if(guess > nombreMystere) printf("Trop Haut\n");
round --;
if (round == 0)
{
printf("You Lose.. Dumbass");
break;
}
if (guess == nombreMystere) printf("\nGood job !\n");
}
printf("Play again?\n (yes/no): ");
scanf("%s", &answer);
if (answer == 110 || answer == 78) {exit=0;}
}
}
return 0;
}
这里是level.c:
static int selec;
int level(int x)
{
int max, difficulty = selec;
if (difficulty==1){max = 100 ;}
else if (difficulty==2){max = 1000 ;}
else if (difficulty==3){max = 10000 ;}
return max;
}
level.h:
int level(int x);
menu.c:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "menu.h"
int level();
int menu()
{
srand(time(NULL));
int max, nombreMystere, selec;
const int MIN = 1;
while (selec < 1 || selec > 3)
{
printf("\n\nSelect Difficulty level:\n");
printf("1: Level 1\n");
printf("2: Level 2\n");
printf("3: Level 3\n");
scanf("%d", &selec);
level(selec);
printf("\n\n%d\n\n", max);
//if (difficulty==1){max = 100 ;}
//else if (difficulty==2){max = 1000 ;}
//else if (difficulty==3){max = 10000 ;}
//else {printf("Wrong selection, please try again.");}
nombreMystere = (rand() % (max - MIN + 1)) + MIN;
}
return nombreMystere;
}
menu.h:
int menu();
我整天都在互联网上搜索解决此问题的方法,但我不明白我所看到的一半,每个主题都只谈论 C++。我在某处看到它可能来自 VSCode 中的 tasks.json 文件,但它是关于 C++ 主题的。
我正在使用 macOS。
感谢您的宝贵时间。
编辑:.h 和 .c 文件都在不同的文件夹中,并且两个文件夹都在同一个目录中。
【问题讨论】:
-
确保
level.h存在于主代码所在的同一目录中。 -
感谢您的回答,是的,它们都在同一个目录中。
-
你的编辑怎么样?您是使用 IDE 还是从 bash 提示符运行它们?如果您是在 bash 提示符下执行此操作,您是如何运行它的?
-
来自 Visual Studio 代码运行选项。
标签: c json visual-studio-code header fatal-error