【发布时间】:2020-02-25 20:51:02
【问题描述】:
我有一个 C 程序正在打印当前目录中文件的详细信息。它是更具体的 ls 版本。我无法让列用一个空格字符分隔。我的功能如下:
while ( (sd = readdir(dir)) != NULL) {
lstat(sd->d_name, &sfile);
printf("%hu", sfile.st_mode);
printf("%d", sfile.st_nlink);
pwd = getpwuid(sfile.st_uid);
printf("%s", pwd->pw_name);
grp = getgrgid(sfile.st_gid);
printf("%s", grp->gr_name);
printf("%lld", sfile.st_size);
t = sfile.st_mtime;
tmp = localtime(&t);
strftime(MY_TIME, sizeof(MY_TIME), "%Y-%m-%d %H:%M", tmp);
printf("%s", MY_TIME);
printf("%s\n", sd->d_name);
我尝试在 printf 语句中添加 %-1s,但这只会给我一个段错误。如果有人可以帮助我,将不胜感激。谢谢你。
我不能只添加空格,因为当您有例如文件链接编号 > 10 在一列中,而下一列中的链接编号为一位数时,列将不会对齐。
Current output:
16877 5 bobmichaels staff 160 2019-10-30 09:54
16832 23 bobmichaels staff 736 2019-10-29 22:24
Desired output:
16877 5 bobmichaels staff 160 2019-10-30 09:54
16832 23 bobmichaels staff 736 2019-10-29 22:24
【问题讨论】:
-
嗨,请编辑问题并显示您现有的输出以及您的期望。