I am trying to make a function like this which will print out the error details associated with it's error number, but i am getting the error error: expected initializer before 'strerror'
. Here is the code
#include <iostream>
#include <cstring>
static char* messages[] = {
"No error",
"EPERM (Operation not permitted)",
"ENOENT (No such file or directory)",
"ESRCH (No such process)",
};
static const int NUM_MESSAGES = sizeof(messages)/sizeof(messages[0]);
extern "C" char * __cdecl strerror(int errnum)
{
if (errnum < NUM_MESSAGES)
return messages[errnum];
return "Unknown error";
}
int main()
{
int a;
for(a=0;a<5;a++)
{
std::cout<<a<<" "<<strerror(a)<<"\n";
}
return 0;
}
How to solve this problem ? Thanks