LS command in C
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 > LS command in C




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

    LS command in C  
Ondras


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


 
04-20-04 06:34 PM

Do you know how to make 'ls' command in C without using functions from
standart libraries? I can use only printf, scanf and functions
implemented in man getpwnam and man getgrnam.
Thanx a lot.





[ Post a follow-up to this message ]



    Re: LS command in C  
Måns Rullgård


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


 
04-20-04 06:34 PM

ondrejhavlak@centrum.cz (Ondras) writes:

> Do you know how to make 'ls' command in C without using functions from
> standart libraries? I can use only printf, scanf and functions
> implemented in man getpwnam and man getgrnam.

That's impossible.  You need at least opendir() and readdir() also,
unless you're allowed to use scandir().  Are you sure you read the
assignment properly?

--
Måns Rullgård
mru@kth.se





[ Post a follow-up to this message ]



    Re: LS command in C  
Billy N. Patton


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


 
04-20-04 06:34 PM

Needs to be converted to return char**, but this is what I use.

#include <dirent.h>
#include <regexpr.h>
#include <stdio.h>
#include <stdlib.h>

HashTable* ListDirectory(String& in,char* regx)
{
DIR               *dirp;
struct dirent     *dp;
HashTable*        files;
char              *expbuf=NULL;

if (in.IsEmpty())
{
lERROR("Received null pointer.  Expected char*.");
return NULL;
}
files = new HashTable;
dirp = opendir(in.Get());
if (dirp EQ NULL)
{
lERROR_A("Unable to open directory \"%s\".",in.Get());
return NULL;
}
while ( (dp = readdir( dirp )) != NULL )
{
if (regx EQ NULL) files->Put(dp->d_name,(void*)NULL);
else
if ((expbuf = compile(regx,(char*)0,(char*)0)))
if (step(dp->d_name,expbuf)) files->Put(dp->d_name,(void*)NULL);
free(expbuf);
}
closedir( dirp );
return files;
}
/*
main (void)
{
int             i;
list_directory(".",&i,".*\\.c$");
}
*/


Ondras wrote:
> Do you know how to make 'ls' command in C without using functions from
> standart libraries? I can use only printf, scanf and functions
> implemented in man getpwnam and man getgrnam.
> Thanx a lot.


--
___  _ ____       ___       __  __
/ _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
/ _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com






[ Post a follow-up to this message ]



    Re: LS command in C  
Billy N. Patton


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


 
04-20-04 08:35 PM

dirp = opendir(in.Get());  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if (dirp EQ NULL)
{
lERROR_A("Unable to open directory \"%s\".",in.Get());
return NULL;
}
while ( (dp = readdir( dirp )) != NULL ) <<<<<<<<<<<<<<<<<<<<<<<<<<<<

Måns Rullgård wrote:
> ondrejhavlak@centrum.cz (Ondras) writes:
>
> 
>
>
> That's impossible.  You need at least opendir() and readdir() also,
> unless you're allowed to use scandir().  Are you sure you read the
> assignment properly?
>


--
___  _ ____       ___       __  __
/ _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
/ _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com






[ Post a follow-up to this message ]



    Re: LS command in C  
Billy N. Patton


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


 
04-20-04 08:35 PM

Guess I got taken in by a student.  Didn't think this was an assignment
for someone.  I sometimes ask for small functions that someone else has
already done just to keep from writing them.  Spend more time on hte
problem I'm trying to solve that writeing tools to solve them.


Måns Rullgård wrote:
> ondrejhavlak@centrum.cz (Ondras) writes:
>
> 
>
>
> That's impossible.  You need at least opendir() and readdir() also,
> unless you're allowed to use scandir().  Are you sure you read the
> assignment properly?
>


--
___  _ ____       ___       __  __
/ _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
/ _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455,  b-patton@ti.com






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 06:48 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