LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-20-2003, 06:38 AM   #1
os120
LQ Newbie
 
Registered: Oct 2003
Posts: 2

Rep: Reputation: 0
help !!!!


please if anyone has an idea on solving this problem tel me because i really need help before tuesday;
the question is:
write a program in linux that displays names of all the files and directories in your home directory ur program should display name of a file followed by (is a file), or name of a directory followed by (is directory).
the last line of the output of ur program should display total number of files and directories found on ur home directory and total size of all files and directories
.
HINT:u can use system() call with parameter "ls-l>filename" to store output in a temperary file .read this file line by line to get type ,name,and size of each entey (file r directory),make sure u delete the temporary file before terminating ur program.

 
Old 10-20-2003, 06:48 AM   #2
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
An obvious question, what language you are talking about? This will be easy to do using perl, but a little tough(IMO for newbies) in java or c. And I don't think you even need a temp file.

In java, you can do this by reading the contents of the directory, and then displaying whether this is a file or folder.
 
Old 10-20-2003, 06:54 AM   #3
os120
LQ Newbie
 
Registered: Oct 2003
Posts: 2

Original Poster
Rep: Reputation: 0
hi ,,,

i must use c language under linux , i am spending couple of time without knowing how to code it , our dr wants us to use temp file
 
Old 10-20-2003, 07:25 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Please do NOT ask homework question on Linuxquestions.org, that is cheating. you need to use the resources available to you, not get someone else to do it for you. and please use useful thread titles "help!!!" is no use whatsoever. always try to give a brief explanation of your problem.
 
Old 10-20-2003, 07:40 AM   #5
SaTaN
Member
 
Registered: Aug 2003
Location: Suprisingly in Heaven
Posts: 223

Rep: Reputation: 33
Here are some of the functions which can help you
1.scandir
2.stat

Run these commands on the command prompt
Quote:
man scandir
man 2 stat
Info about these two commands will be given .
These will help you get what you want. If you have any doubts regarding this feel free to ask me.
 
  


Reply



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



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:39 PM.

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
Open Source Consulting | Domain Registration