C program under Linux

Need help with C, C++, perl, python, etc?

C program under Linux

Postby JoeyMoey » 2017-01-05 18:30

I have recently(yesterday) started trying to learn linux and to program in this os. Now, one interesting and probably easy problem I came across while surfing the net was something like this:

Consider a C program that takes a directory as an argument in the command line and calculates the sum of all the files' dimensions that are in the directory's tree.

Now, due to the fact that I've been doing a lot of reading and researching in a short matter of time, all my knowledge is piled up in my brian creating a cloud of confusion. If anyone could help me with the code, I'd be really thankful.
JoeyMoey
 
Posts: 2
Joined: 2017-01-05 18:29

Re: C program under Linux

Postby dasein » 2017-01-05 18:33

Homework is intended to help you learn to do it yourself, not to have someone else do it for you.
User avatar
dasein
 
Posts: 7635
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: C program under Linux

Postby JoeyMoey » 2017-01-05 18:37

dasein wrote:Homework is intended to help you learn to do it yourself, not to have someone else do it for you.


Hey. It is not homework, I assure you :D
JoeyMoey
 
Posts: 2
Joined: 2017-01-05 18:29

Re: C program under Linux

Postby Segfault » 2017-01-05 18:41

In anther forum you posted a copy of this post and requested code instead of help.
Segfault
 
Posts: 412
Joined: 2005-09-24 12:24

Re: C program under Linux

Postby dasein » 2017-01-05 18:57

JoeyMoey wrote:Hey. It is not homework, I assure you :D

Yes it is, and recognizably so.

Achieving the stated goal in *nix doesn't actually require so much as a single, solitary line of C code. Not even one. So the only reason to do it in C is as a pedagogical exercise.

DYODH. Seriously.

Edit: Some pinhead over @ stackexchange did most of the assignment for him. (A$$hat.)
Last edited by dasein on 2017-01-05 19:35, edited 1 time in total.
User avatar
dasein
 
Posts: 7635
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: C program under Linux

Postby GarryRicketson » 2017-01-05 19:35

No need for a C program, the 'ls' command is all you need,
Code: Select all
man ls


Code: Select all
~$ ls -h -l -s
total 1.2G
1.8M -rw-r--r--  1 garry garry 1.8M Oct 21 11:56 1-OpenBsd-test.gif
180K -rw-r--r--  1 garry garry 17
1.1G -rw-r--r--
###snipped, produces a list of the files,and sizes ,in the directory, as well as the total size


Post by JoeyMoey » 2017-01-05 12:30
I have recently(yesterday) started trying to learn linux and to program in this os.

You just started yesterday ? Read some tutorials on basic linux commands.
JoeyMoey wrote:
Hey. It is not homework, I assure you :D

Then what is it ?
To help you gets started with the C programming:
https://linuxconfig.org/c-development-on-linux-introduction-i
Some searches will find more tutorials, if you do not like that one.
C program under Linux
User avatar
GarryRicketson
 
Posts: 4069
Joined: 2015-01-20 22:16
Location: Durango, Mexico


Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable