-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, 18 Sep 2010, Eric Basile wrote:

I've only been on this list a short while (since about January) and have
never made a post until today since you guys may my best bet for help. For
my Linux/Unix class my teacher wants us to do a simple rewrite of ls (mine
I'm calling els since my name is Eric). So far everything is working
correctly except when i try to use it giving it two command line arguments
(ex".$:./els -l ~") instead of giving a detailed list of my home directory
it gives a shorter detailed list of current directory and I'm not sure why.

        I know why. But in interest of not doing your homework for you, I'll
just start you off with a recommendation that should help you figure it out
yourself:

        Fail noisily and informatively. Several of the standard functions
you're using set errno when they fail. Checking their return value is a
start, but don't just report a generic "Error", and *especially* don't just
skip silently to the next loop iteration without reporting *anything*. When
you get a bad return value, announce it loudly, and *call perror()*. Let the
program tell you what's actually failing, and *why*. This gives you
something to work with when debugging.

        Once you're armed with that information, here's a second hint:
readdir() returns a bare filename, not a full path.

        And on an unrelated note, I don't recommend omitting the braces
around single-statement code blocks, even though you technically can. It's
easy to create non-obvious bugs by forgetting to add them if you expand the
code block.

- -- John Campbell
[email protected]

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkyWbj8ACgkQPu/PJk2ePZ1joACfZBy6Altj3UbZXXRdXH1M8x+7
JbsAoLzB7D+/5cwVZyCzFJhUDIc6AH6G
=m1+X
-----END PGP SIGNATURE-----

Reply via email to