【有图有真相!!!】自己正在做的一个游戏物理引擎~~
时间:2011-04-21
来源:互联网
代码:
#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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28