代码: 全选
#include "apue.h"
#include <sys/stat.h>
int main(int argc, char *argv[])
{
int i;
struct stat buf;
char *ptr;
for (i=1; i<argc; i++)
{
printf("%s: ", argv[i]);
if (stat(argv[i], &buf) < 0)
{
printf("lstat errno\n");
continue;
}
if (S_ISREG(buf.st_mode))
ptr="regular";
else if (S_ISDIR(buf.st_mode))
ptr="directory";
else if (S_ISCHR(buf.st_mode))
ptr="character special";
else if (S_ISBLK(buf.st_mode))
ptr="block special";
else if (S_ISFIFO(st_mode))
ptr="fifo";
else if (S_ISLNK(st_mode))
ptr="symbolic link";
else if (S_ISSOCK(st_mode))
ptr="socket";
else
ptr="unkown mode";
printf("%s\n", ptr);
}
return 0;
}
APUE上的一段代码,编译时报错:
4-1.c: In function ‘main’:
4-1.c:27: error: ‘st_mode’ undeclared (first use in this function)
4-1.c:27: error: (Each undeclared identifier is reported only once
4-1.c:27: error: for each function it appears in.)
为什么说st_mode未声明?
百思不得其解,请指教。