当前位置: 技术问答>linux和unix
PATH_MAX没有定义
来源: 互联网 发布时间:2017-01-14
本文导语: #include #include #include #include #include main() { int n; struct hostent *h; char **p; char hostname[PATH_MAX]; if(gethostname(hostname,PATH_MAX) h_name); for(n=0,p=h->h_aliases; *p != NULL; p++,n++) { ...
#include
#include
#include
#include
#include
main()
{
int n;
struct hostent *h;
char **p;
char hostname[PATH_MAX];
if(gethostname(hostname,PATH_MAX) h_name);
for(n=0,p=h->h_aliases; *p != NULL; p++,n++)
{
fprintf(stderr,"Alias name %d:%sn",n+1,*p);
}
for(n=0; nh_length/sizeof(int); n++)
{
fprintf(stderr,"Ip address %d:%sn",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
#include
#include
#include
main()
{
int n;
struct hostent *h;
char **p;
char hostname[PATH_MAX];
if(gethostname(hostname,PATH_MAX) h_name);
for(n=0,p=h->h_aliases; *p != NULL; p++,n++)
{
fprintf(stderr,"Alias name %d:%sn",n+1,*p);
}
for(n=0; nh_length/sizeof(int); n++)
{
fprintf(stderr,"Ip address %d:%sn",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如何修改?
|
PATH_MAX 是在windef.h文件中定义。。需要包括些文件或者
自行定义
#define MAX_PATH 260
自行定义
#define MAX_PATH 260
|
自行定义
#define MAX_PATH 260
|
试试#include
|
#include
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。