C program under Linux

Programming languages, Coding, executables, and scripting.
Post Reply
Message
Author
JoeyMoey
Posts: 2
Joined: 2017-01-05 18:29

C program under Linux

#1 Post by JoeyMoey »

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.

User avatar
dasein
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: C program under Linux

#2 Post by dasein »

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

JoeyMoey
Posts: 2
Joined: 2017-01-05 18:29

Re: C program under Linux

#3 Post by JoeyMoey »

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

Segfault
Posts: 914
Joined: 2005-09-24 12:24

Re: C program under Linux

#4 Post by Segfault »

In anther forum you posted a copy of this post and requested code instead of help.

User avatar
dasein
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: C program under Linux

#5 Post by dasein »

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
GarryRicketson
Posts: 5872
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: C program under Linux

#6 Post by GarryRicketson »

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-o ... oduction-i
Some searches will find more tutorials, if you do not like that one.
C program under Linux

Post Reply