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

This is a discussion on concatentating dirent.h dname from dirent.h to the path in C within the Linux Programming forums, part of the Platform Specific Boards category; Hello, I am trying to open using fd the full path of my file and get the name of input ...

  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,265
    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, 06:32 PM
  3. Path Finding Using Adjacency List.
    By DeepBlackMagic in forum C++ Programming
    Replies: 7
    Last Post: 05-16-2005, 03: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, 04:00 PM
  5. linked list recursive function spaghetti
    By ... in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2003, 03:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21