Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
#include <stdio.h> 


char * GetRomanNumber(char*numbers[],int i);

void main()
{
    char *units[] = { "", "I","II","III","IV","V","VI","VII","VIII","IX" };

    char *tens[] = { "", "X","XX","XXX","XL","L","LX","LXX","LXXX","XC" };

    char *hundreds[] = {"",  "C","CC","CCC","CD","D","DC","DCC","DCCC","CM" };

    char *thousands[] = {"",  "M","MM","MMM" };
    
    int n;
    printf("Enter number: ");
    scanf("%d", &n);

    int u,t,h,th;

    u = n % 10;
    t = (n / 10)%10;
    h = (n / 100)%10;
    th = (n / 1000)%10;

    printf("%s",GetRomanNumber(thousands,th));
    printf("%s",GetRomanNumber(hundreds,h));
    printf("%s",GetRomanNumber(tens,t));
    printf("%s",GetRomanNumber(units,u));

    printf("\n");
}



 char * GetRomanNumber(char*numbers[],int i)
 {
     return numbers[i];
 }


I've got code that looks like this. But when I run it it gives me two errors,
function declaration isn’t a prototype
, and
return type of ‘main’ is not ‘int’
. What do these mean and how do I fix them?

What I have tried:

Not much, changing stuff just causes other errors so I'm asking here.
Posted
Updated 5-Oct-21 20:09pm

Quote:
return type of ‘main’ is not ‘int’

Even if void is C legal for main routine, your compiler want to enforce current usage which is int main.
 
Share this answer
 
To add to what PAtrice has said, a function prototype (and known as a forward definition in many cases) is the signature of the function: the name, the parameters it requires when you call it, and the return type. So
C
int foo (double);
Prototypes a function called foo which needs a single double parameter, and which returns an int value.

When you compile, the system adds two function prototypes for you:
C
int main(void);
And
C
int main(int argc , char *argv);
Some systems do add
C
void main(void);
But that's pretty rare and your system doesn't do that.
If your definition of main doesn't meet one of the "predefined prototypes" then you get the errors you show.

It is very important in C to get your prototypes and functions to match up - it's an old language, and it doesn't support overloading, which allows the same function name with different parameter lists to exist side by side.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900