怎样更改使其查看当前目录下的bmp文件
时间: 2024-03-07 15:49:39 浏览: 24
要让这个代码查看当前目录下的 BMP 文件,只需要将 `opendir` 函数中传入的目录参数 `argv[1]` 改为 `"."`,就可以打开当前目录了。修改后的代码如下:
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/mman.h>
#include <linux/input.h>
#include <errno.h>
#include <dirent.h>
//设置节点
struct node {
char *data;
struct node *next;
struct node *prev;
};
//初始化链表
struct node *list_init() {
struct node *head = malloc(sizeof(struct node));
head->next = head;
head->prev = head;
return head;
}
//创建新节点
struct node *newnode(char *newdata) {
struct node *new = malloc(sizeof(struct node));
new->data = newdata;
new->next = NULL;
new->prev = NULL;
}
//加入新节点
int addnode(struct node *new,struct node *list) {
struct node *p = list;
while(p->next != list)
{
p = p->next;
}
new->prev = list->prev;
new->next = list;
list->prev = new;
new->prev->next = new;
}
int main(int argc,char **argv) {
struct node *list = list_init();
DIR *dp = opendir("."); // 打开当前目录
struct dirent *p;
while(p = readdir(dp))
{
if(p->d_type == DT_REG) {
if(strstr(p->d_name, ".bmp")) {
struct node *new = newnode(p->d_name);
addnode(new, list);
}
}
}
}
```
相关推荐
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)