ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
while( (dirent_ptr = readdir(dir_ptr)) != NULL )
{
//printf("i-node: %ld - ", dirent_ptr->d_ino);
//printf("filename: %s\n", dirent_ptr->d_name);
if ( stat(dirent_ptr->d_name, &boo_buf) < 0 )
{
perror(dirent_ptr->d_name);
exit(1);
}
// OK till here
// result SHOULD be 0, if file matches with . [but it IS NOT!!] :(
int result;
printf("%s\n",dirent_ptr->d_name);
result = strcmp(dirent_ptr->d_name, ".") ;
printf("%i\n",result);
eventhough dirent_ptr->d_name is in the beginning . result DOES NOT become 0
if I have ".." then it becomes 0 [in the second time of the loop]
so I guess the strcmp doesn't like the "."??
I tried '.' GCC doesn't like it now!
I'm forced to write in C. Oh boy! in C# one could just write != , ==
well I know the Power of C in the low-level, that's why I want your help in this [and not only] but this is the basic to continue :P
oh yes. the code has some addition to make it easy to understand and to help!
plz propose me a solution. I know it's %s :P
I also know that C++ does the trick.
a C only solution would rock
It is strange that strcmp is returning 1 on "." but 0 on ".." I have tried it hear and it is the other way around, something weird going on in your setup
To be honest I'm not sure that code will work. dirent_ptr->d_name == ".." your comparing the pointer to a constant array. Theres also stuff that could start .thishere as well.
anyways, the point is that now it's working as expected, and the problem is afterwards [should write an algorithm that will check for the files in a dir, and check some of those files are Dirs, and if they are it should open them etc.. go deep in a recurvise implementation..]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.