[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C stuff




I'm not exactly sure how you'd do this, but, I do know that you can rarely
ever do assignments in the way you're trying.  You first need to look at
what system() returns.  Excerpt from the man page for system():

RETURN VALUE
       The value returned is 127 if the execve() call for /bin/sh fails, 
       -1 if there was another error and the return code of the command 
       otherwise.

       If  the  value of string is NULL, system() returns nonzero if the
       shell is available, and zero if not.  system() does not affect the
       wait status of any other children.


So, it's returning integers, not chars (as I'm guessing that array is
declared).  Your best bet for returning information about a directory
would be the actually reading it from the file system.  Look at the man
page for getdents().  That would probably give you exactly what you're
looking for.  

On another note, I must remind those of you trying things like this, C is
a more "low-level" language than perl and other extraction languages of
this type (Perl was written in C itself).  You normally cannot just assign
a character array to a function, and get what you want.  You'll usually
have to painfully extract it at the lowlevel, or, if the function does
happen to return a char, you'll probably have to use strcpy() or strncpy()
(preferred) to copy the information to the array.  Always look at what
values a function returns before assigning a variable to the function.
It'll save you a lot of headaches in the end.  If you want more detail on
getdents(), I can go further into it later :D

Koree

---------------------------------------------
Koree A. Smith  | Co-Administrator, Ameth.org
koree@Ameth.org | http://www.ameth.org/~koree       
NT != *IX       | I Corinthians 2:1-5
---------------------------------------------


On Sun, 29 Mar 1998, Bill Dunn wrote:

> 
> 
> 	What would be the equivalent in ANSI C or C++ to the following PERL line:
> 
> 	$input = `ls -l /home/httpd/html`;
> 
> 	I've tried:
>  
>  	input[1000] = system("ls -l /home/httpd/html");
> 
> 	but it actually sends the output to the screen instead of the assigning
> 	the directory listing to the variable. And I've tried several data types
> 	for input to no avail.
> 
> 	Basically, all I need to do is get a list of the files in a directory
> 	and assign them to an array so I can use them one at a time.
> 
> 	Thanks.
> 
> 
> 	Bill Dunn
> 
> --
> To unsubscribe, send email to majordomo@silug.org with
> "unsubscribe silug-discuss" in the body.
> 


--
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.