LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2012, 10:46 AM   #1
laffytaffykidd
LQ Newbie
 
Registered: Sep 2012
Posts: 1

Rep: Reputation: Disabled
Need help writing the ls command in C


Hey everybody this is my first post here, and I know that it would be beneficial if I also post what I have tried, but the problem is, I'm not sure where to start.

I basically have to write a program in C based on the ls command (showing the current working directory).

So far, I have only looked up man pages for opendir(), readdir(), stat()...
From there, I am still unsure about how I would write the ls command.
I'm a little new to the C language, but I am a little fluent in C++.

Could someone point me in the right direction?
 
Old 09-10-2012, 10:56 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190Reputation: 1190
Quote:
Originally Posted by laffytaffykidd View Post
I basically have to write a program
That phrase implies a homework assignment.

You need to show a little more effort and/or ask more specific questions to expect homework assistance here.

Quote:
So far, I have only looked up man pages for opendir(), readdir(), stat()...
Are there specific details of those functions that you didn't understand from the man pages? That kind of question is OK to ask, even for homework.

Quote:
From there, I am still unsure about how I would write the ls command.
I'm a little new to the C language, but I am a little fluent in C++.
Does that mean you would know how to do it in C++ ?

You could start with a C++ program and then change each part of the program that does something not available in C to do the equivalent operation in a method supported by C. At each such step, you would still have a testable C++ program. At the end of all such steps you could have a program that works equally well in C++ or C.

Do you know how to use printf in C? printf is the same in C++, so you might even know how to use it there, but in C++ there are usually better alternatives to printf, so you might not.

Quote:
Originally Posted by laffytaffykidd View Post
I'm not sure where to start.
If you know any programming at all then how is it possible you don't know where to start? Your program needs to get information and display information. You can't have needed me to tell you to start by dividing your effort into those two areas. You already took the biggest step (or maybe your instructor gave it to you) of selecting functions that are useful for the "get information" part of the task. And you already started by reading the man pages of those functions.

Last edited by johnsfine; 09-10-2012 at 11:09 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
Writing command executed into logfile pandunr Linux - Newbie 1 06-08-2011 02:25 AM
writing 0xFF with the dd command FireRaven Linux - Software 1 11-19-2010 09:07 PM
writing your own command in unix/linux amardeep.sidhu Programming 4 03-15-2007 12:52 PM
while writing your own Bash shell command basak Linux - Software 4 08-02-2006 11:58 AM
Command for writing over files? soulflyer Linux - Newbie 2 12-12-2003 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration