problems compiling with and readdir
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > problems compiling with and readdir




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    problems compiling with and readdir  
shyam


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-21-06 12:24 PM

I have a simple directory reading function

DIR *dir;
struct dirent *dirp;


dir = opendir( /* some valid path */  );
while ( (dirp = readdir( dir )) != NULL )
printf( "%s\n", dirp->d_name );


When I compile it in linux 2.4 with gcc 3.2  I get following error

for line conatining the statement
dir = opendir( /* some valid path */  );
the gcc says "warning: assignment from incompatible pointer type"

and for line
printf( "%s\n", dirp->d_name );
it says " dereferencing pointer to imcomplete type"

i tried with including dirent.h as well as sys/dir.h but no lick

it is such a simple thing and atill not working ,
any help will be appreciated

thanks






[ Post a follow-up to this message ]



    Re: problems compiling with and readdir  
loic-dev@gmx.net


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-21-06 12:24 PM

Hello,

> I have a simple directory reading function
>
> DIR *dir;
> struct dirent *dirp;
>
>
> dir = opendir( /* some valid path */  );
>  while ( (dirp = readdir( dir )) != NULL )
>          printf( "%s\n", dirp->d_name );
>
>
> When I compile it in linux 2.4 with gcc 3.2  I get following error
>
> for line conatining the statement
> dir = opendir( /* some valid path */  );
> the gcc says "warning: assignment from incompatible pointer type"
>
> and for line
> printf( "%s\n", dirp->d_name );
> it says " dereferencing pointer to imcomplete type"
>
> i tried with including dirent.h as well as sys/dir.h but no lick
>
> it is such a simple thing and atill not working ,
> any help will be appreciated

Do you include the two following headers?
#include <sys/types.h>
#include <dirent.h>

You can find out the header(s) to include on your system for a
particular API using the man pages:
$ man opendir

Or, alternatively, for portable programs, you can read the Single Unix
Specification:
http://www.unix.org/version3/online.html

Cheers,
Loic.






[ Post a follow-up to this message ]



    Re: problems compiling with and readdir  
shyam


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-21-06 12:24 PM


loic-dev@gmx.net wrote:
> Hello,
> 
>
> Do you include the two following headers?
> #include <sys/types.h>
> #include <dirent.h>

yes , I have included both the headers
also tried with sys/dir.h

but in vein

>
> You can find out the header(s) to include on your system for a
> particular API using the man pages:
> $ man opendir
>
> Or, alternatively, for portable programs, you can read the Single Unix
> Specification:
> http://www.unix.org/version3/online.html
>
> Cheers,
> Loic.






[ Post a follow-up to this message ]



    Re: problems compiling with and readdir  
Darko


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-21-06 12:24 PM

Did you try looking at your man pages? Look for "man opendir", see
which headers you should include, and what types it needs.

shyam wrote:[vbcol=seagreen]
> loic-dev@gmx.net wrote: 
>
> yes , I have included both the headers
> also tried with sys/dir.h
>
> but in vein
> 






[ Post a follow-up to this message ]



    Re: problems compiling with and readdir  
Bjorn Reese


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
11-22-06 12:27 PM

shyam wrote:

> When I compile it in linux 2.4 with gcc 3.2  I get following error
>
> for line conatining the statement
> dir = opendir( /* some valid path */  );
> the gcc says "warning: assignment from incompatible pointer type"

The following worked just fine on Linux 2.4.22 with gcc 3.2.2.

#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

int main(void)
{
DIR *dir;
struct dirent *dirp;

dir = opendir(".");
if (dir) {

while ( (dirp = readdir( dir )) != NULL )
printf( "%s\n", dirp->d_name );

closedir(dir);
}

return 0;
}


--
mail1dotstofanetdotdk





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:52 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register