I keep getting an error of multiple definition of main for armstrong numbers task. How i can i solve this in C.
Here on Exercism you don’t have to implement a whole program (with a main()
function), you just have to declare/define one or multiple functions. Your solution and the tests gets compiled together into a program that runs all the tests.
Initially the the file armstrong_numbers.h
looks like this:
#ifndef ARMSTRONG_NUMBERS_H
#define ARMSTRONG_NUMBERS_H
#include <stdbool.h>
bool is_armstrong_number(int candidate);
#endif
As you can see it already declares the function is_armstrong_number()
.
The file armstrong_numbers.c
initially looks like this:
#include "armstrong_numbers.h"
Here you have to define the function that is declared in the .h
file.
Hey the int main is for the print f and scan f to recieve user input or do i need to do away with it.
int main(void) {
int n;
printf(“Enter a number to check if it is an Armstrong number: “);
scanf(”%d”, &n);
if (is_armstrong_number(n)) {
printf(“%d is an Armstrong number.\n”, n);
} else {
printf(“%d is not an Armstrong number.\n”, n);
}
return 0;
make test
will take care for the right compiler paramters. When you write a main function you have to compile by your own to run it via command line.
Thanks removing the main function solved the problem. So i guess focus is the solution not the user input as it is in the main functions of test.