【有图有真相!!!】自己正在做的一个游戏物理引擎~~
代码:
#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;
}
#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未声明?
百思不得其解,请指教。
作者: yts 发布时间: 2011-04-21
仔细检查你的代码。部分代码写的不完整。比如
...
else if (S_ISFIFO(st_mode))
...
应该是
...
else if (S_ISFIFO(buf.st_mode))
...
...
else if (S_ISFIFO(st_mode))
...
应该是
...
else if (S_ISFIFO(buf.st_mode))
...
作者: linjiework 发布时间: 2011-04-21
确实是的,看来还是太马虎,谢谢楼上
作者: yts 发布时间: 2011-04-21