Thread: concatentating dirent.h dname from dirent.h to the path in C

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    1

    concatentating dirent.h dname from dirent.h to the path in C

    Hello,

    I am trying to open using fd the full path of my file and get the name of input device.

    But for some reason, the fd is not returning the file i required. I know it is a simple string manipulation but i can not figure it, can some one help??

    thanks

    here is my code snippet

    Code:
    evdev= opendir("/dev/input");
    
    
    while ((Direntry= readdir(evdev)) != NULL) {
    
    
    
    
    
    
    
    
    if ((fd = open("/dev/input/%s" ,Direntry->d_name, O_RDONLY)) > 0) {
    
    ioctl(fd, EVIOCGNAME(sizeof(name)), name);
    
            printf("Input device name: \"%s \" \n",name);
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I think you are looking for sprintf().
    Code:
    char buffer[100];
    sprintf(buffer, "/dev/input/%s", Direntry->d_name);
    open(buffer, ...);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't figure out what keeps hanging up my program
    By shays in forum C Programming
    Replies: 7
    Last Post: 11-12-2007, 02:59 PM
  2. Shortest path problem
    By Digitalxero in forum C++ Programming
    Replies: 0
    Last Post: 10-25-2005, 05:32 PM
  3. Path Finding Using Adjacency List.
    By Geolingo in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2005, 02:34 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 02:53 PM