我在大学的第一个学期学习 C 编程。我们已经获得了模块化代码的介绍,我的问题的基本要点是我创建了一个提示用户继续或退出程序的函数。显然,在此之前我还有其他一些函数,我在 main() 中调用它们。请记住,这些函数位于单独的 C 文件中。如果用户输入“Y”(即从头开始启动程序),我希望循环回到 main(),但鉴于我的初学者知识,我很难弄清楚如何去做。任何帮助/指导将不胜感激!
int continueOrExit() {
char response;
char upperResponse;
printf("Do you wish to continue the program? Y/N");
scanf("%c", &response);
upperResponse = toupper(response);
while(upperResponse == 'Y')
main(); // this is the bit which I struggle with
.....
}
Run Code Online (Sandbox Code Playgroud)