The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command to list directory names only stevefox UNIX for Dummies Questions & Answers 6 11-29-2007 05:06 PM
how to list a directory & file gagasan_makmur UNIX for Dummies Questions & Answers 2 09-26-2006 09:40 PM
Directory list inside a directory little_jhon UNIX for Dummies Questions & Answers 6 01-14-2006 10:05 AM
list of files in one Directory venkyA UNIX for Dummies Questions & Answers 3 06-24-2005 01:49 PM
can we list other than c files in a directory with only 'ls' command? venkat UNIX for Dummies Questions & Answers 3 03-12-2004 06:17 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-22-2004
Registered User
 

Join Date: May 2004
Posts: 2
list directory without use ls command?

Hi
i need C code to list direcoty without using ls command and it sould take the path of the directory from the user?

"please help me it is so important"
Forum Sponsor
  #2  
Old 05-22-2004
Registered User
 

Join Date: May 2004
Posts: 15
#include <stdio.h>
#include <string.h> // for access
#include <fcntl.h>
#include <dirent.h> // for struct dirent
#include <sys/stat.h> //for struct stat and the functions related to it

int main(int argc, char **argv)
{
struct dirent *dp;
DIR *dirp; // structure for the directory

if(argc != 2) {
fprintf(stderr, "Usage: ./a.out dirName");
exit(1);
}

dirp=opendir(argv[1]);
while((dp=readdir(dirp))!= NULL)
printf("%s\n", dp->d_name);
}
  #3  
Old 06-07-2004
Registered User
 

Join Date: May 2004
Posts: 2
thanx for your help but i need that with out using C function also
like "printf(),opendir()", it must use system calls only like "read(),write"
  #4  
Old 06-08-2004
Driver's Avatar
Registered User
 

Join Date: Jul 2001
Location: Bremen, Germany
Posts: 34
The artificial restriction tells us that this is a homework assignment. If you read the unix.com rules:

Simple rules of the UNIX.COM forums:

... you'll see that homework assignments do not belong here, so I'll close the thread. Tell your teacher what you're having problems with and I'm sure he'll help you out.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0