#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>
#include <dirent.h>
typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;
int main(int argc, const char *argv[])
{
DIR* dp = opendir("./2");
int fd = open("1.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
if(dp==NULL){
perror("opendir");
return 1;
}
while(1){
struct dirent* file = readdir(dp);
if(file==NULL){break;}
printf("%s\n",file->d_name);
write(fd,file,sizeof(file));
}
close(fd);
return 0;
}
文件里面全是乱码,结果失败,太遗憾了