小编use*_*505的帖子

在bytearray上打印

我有以下结构:

/** The description of an ordinary 8+3 DOS directory entry. */
struct  dirent
{
    byte    d_name[8];  //!< space padded name
    byte    d_ext[3];   //!< space padded extension

    byte    d_attr;     //!< the file attributes

    ......
};

printf("%s\n", de.d_name);
Run Code Online (Sandbox Code Playgroud)

我面临的问题是打印d_name我得到以下输出: 'INSTALL BAT!' 这不是我最想要的8个字符.

我的猜测是printf函数继续在内存中搜索字符串终止符,即使它超出了d_name边界.

有没有办法只打印'INSTALL'或者我是否需要遍历整个字节数组并单独打印字符?

c printf

6
推荐指数
1
解决办法
4978
查看次数

从列表python中删除文件名

我在名为files的列表中有一个目录的所有文件名.我想过滤它,所以只剩下扩展名为.php的文件.

for x in files:
    if x.find(".php") == -1:
        files.remove(x)
Run Code Online (Sandbox Code Playgroud)

但这似乎跳过了文件名.我该怎么办?

python

1
推荐指数
2
解决办法
140
查看次数

标签 统计

c ×1

printf ×1

python ×1