PATH_MAX没有定义
时间:2011-07-07
来源:互联网
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
main()
{
int n;
struct hostent *h;
char **p;
char hostname[PATH_MAX];
if(gethostname(hostname,PATH_MAX) < 0)
{
fprintf(stderr,"gethostname failed:%s\n",strerror(errno));
exit(0);
}
if((h = gethostbyname(hostname)) == NULL)
{
fprintf(stderr,"gethostbyname failed:%s\n",strerror(errno));
exit(0);
}
fprintf(stderr,"Host name:%s\n",h->h_name);
for(n=0,p=h->h_aliases; *p != NULL; p++,n++)
{
fprintf(stderr,"Alias name %d:%s\n",n+1,*p);
}
for(n=0; n< h->h_length/sizeof(int); n++)
{
fprintf(stderr,"Ip address %d:%s\n",n+1,inet_ntoa(*((struct in_addr *)(h->h_addr_list[n]))));
}
return;
}
这段程序在使用gcc编译以后出现如下信息:
host.c: In function ‘main’:
host.c:11:19: error: ‘PATH_MAX’ undeclared (first use in this function)
host.c:11:19: note: each undeclared identifier is reported only once for each function it appears in
host.c:15:9: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
host.c:21:9: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
host.c:32:69: warning: format ‘%s’ expects type ‘char *’, but argument 4 has type ‘int’
PATH_MAX如何定义?这段程序的第15、21、32行的warning如何修改?
#include <stdlib.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
main()
{
int n;
struct hostent *h;
char **p;
char hostname[PATH_MAX];
if(gethostname(hostname,PATH_MAX) < 0)
{
fprintf(stderr,"gethostname failed:%s\n",strerror(errno));
exit(0);
}
if((h = gethostbyname(hostname)) == NULL)
{
fprintf(stderr,"gethostbyname failed:%s\n",strerror(errno));
exit(0);
}
fprintf(stderr,"Host name:%s\n",h->h_name);
for(n=0,p=h->h_aliases; *p != NULL; p++,n++)
{
fprintf(stderr,"Alias name %d:%s\n",n+1,*p);
}
for(n=0; n< h->h_length/sizeof(int); n++)
{
fprintf(stderr,"Ip address %d:%s\n",n+1,inet_ntoa(*((struct in_addr *)(h->h_addr_list[n]))));
}
return;
}
这段程序在使用gcc编译以后出现如下信息:
host.c: In function ‘main’:
host.c:11:19: error: ‘PATH_MAX’ undeclared (first use in this function)
host.c:11:19: note: each undeclared identifier is reported only once for each function it appears in
host.c:15:9: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
host.c:21:9: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’
host.c:32:69: warning: format ‘%s’ expects type ‘char *’, but argument 4 has type ‘int’
PATH_MAX如何定义?这段程序的第15、21、32行的warning如何修改?
作者: scintist2010 发布时间: 2011-07-07
PATH_MAX 是在windef.h文件中定义。。需要包括些文件或者
自行定义
#define MAX_PATH 260
自行定义
#define MAX_PATH 260
作者: c395565746c 发布时间: 2011-07-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28