LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2004, 09:36 AM   #1
jupe
LQ Newbie
 
Registered: Jul 2004
Posts: 2

Rep: Reputation: 0
readdir then read the files


What is not working in that code??? Can anybody help me please!!!!!

int main( int argc, char ** argv )
{

int num,i;
char buf[10000];
setbuf(stdin,buf);
FILE *fp;

DIR * dir = opendir("/dir/path");

if( dir )
{
dirent * entry;
while( entry = readdir( dir ) )
{
printf("%s\n",entry->d_name);
sprintf(buf, "%s/%s","/dir/path",entry->d_name);
fp = fopen(entry->d_name, "r");
fclose(fp);

}
return 0;
}
else
{
printf("Couldn't open dir");
return -1;
}
int closedir(DIR * dir);
}
 
Old 07-13-2004, 10:02 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
do a perror after every system call that you call ....perhaps that directory is not even present. are you including all the correct headers? to get the compilation done atleast?
is it compiling fine?
isf yes where do you get the error?
 
Old 07-13-2004, 10:04 AM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Your fopen() call needs to use buf instead of entry->d_name. I typo'd the code that I posted in your other thread. My apologies.

Your closedir() call is also a little whacked. You should change it to just closedir(dir);. Right now it looks like a function prototype.

Last edited by itsme86; 07-13-2004 at 10:06 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mozzla problems-can not read files online, can not read attachments sarajevo Linux - Software 1 09-20-2005 06:58 PM
about readdir r_213 Programming 1 01-16-2005 11:26 PM
How program to read files with extension .dat y .cfg files COMTRADE in fedora 1? ivonne Linux - Software 0 11-22-2004 11:42 AM
after readdir how can I open all the files jupe Programming 1 07-13-2004 09:00 AM
using readdir to display files sutho1 Programming 2 10-10-2003 09:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration