error: 'NULL' and 'stderr' undeclared

OP (Company: Home) #5052367
Rate this post
useful
not useful
I'm using gcc 4.6.0 for armv7. Today I needed to compile this source:
#include <sys/types.h>
#include <dirent.h>

int main(void)
{
DIR *dir = opendir(".");
if(dir)
{
struct dirent *ent;
while((ent = readdir(dir)) != NULL)
{
puts(ent->d_name);
}
}
else
{
fprintf(stderr, "Error opening directory\n");
}
return 0;
}

At compilation there were here such errors:
test.c: In function 'main':
test.c:10:31: error: 'NULL' undeclared (first use in this function)
test.c:10:31: note: each undeclared identifier is reported only once for 
each function it appears in
test.c:17:1: warning: incompatible implicit declaration of built-in 
function 'fprintf' [enabled by default]
test.c:17:9: error: 'stderr' undeclared (first use in this function)

What am I doing wrong?

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now