关于对每个命令行参数打印文件类型的程序的问题
这个程序使用来 打印每个命令行参数的文件类型 但是当打印/dev/log文件出现乱码#include <stdio.h>#include <stdlib.h>
#include <sys/stat.h>
#define _GNU_SOURCE
int main(int argc,char *argv[])
{
int i;
struct stat buf;
char *ptr;
for(i=1;i<argc;i++){
printf("%s: ",argv);
if(lstat(argv,&buf)<0) {
printf("lstat error");
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="char special";
else if(S_ISBLK(buf.st_mode))
ptr="blick special";
else if(S_ISFIFO(buf.st_mode))
ptr="fifo file";
else if(S_ISLNK(buf.st_mode))
ptr="link file";
else if(S_ISSOCK(buf.st_mode))
ptr-"socket file";
else
ptr="unknow file";
printf("%s\n",ptr);
}
exit(0);
}
else if(S_ISSOCK(buf.st_mode))
ptr-"socket file"; 回复 2# linux_c_py_php
额。。呢编译器居然没有报错!!
页:
[1]