【发布时间】:2020-08-23 21:38:41
【问题描述】:
Gcc 给出错误“functions.c: In function 'retryop': functions.c:109:3:警告:函数'main'的隐式声明 [-Wimplicit-function-declaration] 主要的(); ^~~~”
我正在创建一个回调 main 以重新启动文件的函数,但我不知道如何让它返回,因为 main 是在我的函数文件之后声明的。对此的任何帮助将不胜感激。
Main.c
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include "functions.c"
int main()
{
setup();
char type;
double number1;
double number2;
int temp;
bool retry;
printf("Please choose what operation you would like to do ( +, -, *,/, or R): \n");
scanf("%c", &type);
if (type == '+')
{
setup();
printf("Addition\n");
printf("\n");
printf("Please enter Addend 1:");
scanf("%lf", &number1);
printf("Please enter Addend 2:");
scanf("%lf", &number2);
double answer = number1 + number2;
printf("The Sum is: %f", answer);
retryop();
}
else if (type == '-')
{
setup();
printf("Subtraction\n");
printf("\n");
printf("Please enter Your Minuend:");
scanf("%lf", &number1);
printf("Please enter Your Subtrahend:");
scanf("%lf", &number2);
double answer = number1 - number2;
printf("The Differnce is: %f", answer);
retryop();
}
else if (type == '*')
{
setup();
printf("Muliplication\n");
printf("\n");
printf("Please enter Factor 1:");
scanf("%lf", &number1);
printf("Please enter Factor 2:");
scanf("%lf", &number2);
double answer = number1 * number2;
printf("Your Product is: %f", answer);
retryop();
}
else if (type == '/')
{
setup();
printf("Division\n");
printf("\n");
printf("Please enter your divadend:");
scanf("%lf", &number1);
printf("Please enter your divisor:");
scanf("%lf", &number2);
double answer = number1 / number2;
printf("Your quotient is: %f", answer);
retryop();
}
else if (type == 'R')
{
setup();
int maxValue;
srand(time(NULL));
printf("Please enter your max value:");
scanf("%i", &maxValue);
int random = (rand() % (maxValue + 1));
printf("Here is your random number: %i", random);
retryop();
}
else if (type == 'r')
{
setup();
int maxValue;
srand(time(NULL));
printf("Please enter your max value:");
scanf("%i", &maxValue);
int random = (rand() % (maxValue + 1));
printf("Here is your random number: %i\n", random);
retryop();
}
else
{
setup();
printf("Please Re-run your program and enter a valid Operator\n");
system("pause");
Main();
}
}
函数.c
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
char type;
double number1;
double number2;
double answer;
bool retry;
char temp;
void setup()
{
system("cls");
}
int typeselect()
{
printf("Please choose what operation you would like to do ( +, -, *,/, or R): \n");
scanf("%c", &type);
return type;
}
int retryop()
{
printf("Would you like to do this again? [Y/N]");
scanf("%i", &temp);
if (temp == 'Y')
{
system("pause");
Main();
}
else if (temp == 'y')
{
system("pause");
Main();
}
else if(temp == 'N')
{
system("pause");
return 0;
}
else if(temp == 'n')
{
system("pause");
return 0;
}
else
{
system("pause");
return 0;
}
}
【问题讨论】:
-
不要在 main 中编写所有代码。
-
main()不同于Main() -
@Cid 我修复了它,它仍然给出完全相同的错误
-
重复一遍,不要在
main中编码所有内容。为此编写单独的函数。更一般地说,函数需要在使用前声明,参见:warning: implicit declaration of function -
好吧,你还没有在
functions.c中声明main()
标签: c