Help with this C program!!

tkin

Back to school!!
Here's the question, I can't solve this, need help.

Q.Write a C program to pass file path as command line argument and use stat() function to get file stats(time of creation, length, size, name of file) in linux.

This is too hard, the man page for stat is very vague with structures etc, I know stat command for shell but the function is HARD.


PS: On a scale of 1-10 how hard is this program for a 3rd year CS student with very basic linux, and moderate C knowledge?
 

asingh

Aspiring Novelist
Here's the question, I can't solve this, need help.

Q.Write a C program to pass file path as command line argument and use stat() function to get file stats(time of creation, length, size, name of file) in linux.

This is too hard, the man page for stat is very vague with structures etc, I know stat command for shell but the function is HARD.


PS: On a scale of 1-10 how hard is this program for a 3rd year CS student with very basic linux, and moderate C knowledge?

1 = easy.

This thing is like a 2.5...! :)

Enjoy. One function can manage this. Remember parameter passing..!
 
OP
tkin

tkin

Back to school!!
1 = easy.

This thing is like a 2.5...! :)

Enjoy. One function can manage this. Remember parameter passing..!
Maybe to you, but I kinda felt like hell(in compare some of my friends were doing stuff like config firewall from shell etc, got frustrated), issue was when I opened the man page of stat it showed a very big structure and a pointer called *buf, didn't what it meant, I think I should start brushing up my c skills.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Ok, I personally feel someone should not be redirected to Google, if he can't answer the query. Of course we all know googling reveals all the result, but the answer should not be "Google it out dude".

If he was able to "google it out" then he wouldn't have asked it here.

I know the negetive side of this too, many peoples want spoon feeding and doesn't even google a single thing and keeps asking many basic things.

But for @OP I think, may be he's not that advanced and a begineer to solve this program. So we should help him out rather than just posting "Google It Out".

Correct me if I'm wrong.

BTW don't mind this OT.

BTW @OP check this out stat (C System Call) - Code Wiki

It's exactly same what you want.
 
OP
tkin

tkin

Back to school!!
Ok, I personally feel someone should not be redirected to Google, if he can't answer the query. Of course we all know googling reveals all the result, but the answer should not be "Google it out dude".

If he was able to "google it out" then he wouldn't have asked it here.

I know the negetive side of this too, many peoples want spoon feeding and doesn't even google a single thing and keeps asking many basic things.

But for @OP I think, may be he's not that advanced and a begineer to solve this program. So we should help him out rather than just posting "Google It Out".

Correct me if I'm wrong.

BTW don't mind this OT.

BTW @OP check this out stat (C System Call) - Code Wiki

It's exactly same what you want.
Thanks for the link and yes, googling does not help, the link that guy posted above directs to a page where you can see the question but to see the answer you have to pay and sing up and its not what I need, I did the program almost like this but was having some issues with improper type casting as I didn't declare argv as double pointer and a few more niggles.

PS: In college we have to code on linux using vi/gedit and gcc, so the debug messages are pretty hard to understand.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
PS: In college we have to code on linux using vi/gedit and gcc, so the debug messages are pretty hard to understand.

Wow...!! From when did colleges started teaching programming under Linux. Damn lucky man.

BTW GDB is the debugger for GCC(Linux). Use it and after that debugging won't be hard anymore.

gdb - Google Search
 
OP
tkin

tkin

Back to school!!
Wow...!! From when did colleges started teaching programming under Linux. Damn lucky man.

BTW GDB is the debugger for GCC(Linux). Use it and after that debugging won't be hard anymore.

gdb - Google Search
Our college is very cheap to license winxp(and I believe the ones running are pirated), anyway theres this whole linux mood going on, we have to do everything on linux(its even in our syllabus, the OS and System Administrator is taught to us on linux), and our HOD is a linux freak. So you can guess.

Will try GDB for sure.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Damn lucky man.

Wish I'd also have learned programming under Linux.

Anyway Happy Coding.

@LFC_fan Thanks for the cleanup man. They were not adding any values to the discussion I guess.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
^^I guess the link had question but not the answer, and you need to pay to view the answer.

Anyway it's not like that, It was just a clean up which didn't added any value.
 

abhijangda

Padawan
Our college is very cheap to license winxp(and I believe the ones running are pirated), anyway theres this whole linux mood going on, we have to do everything on linux(its even in our syllabus, the OS and System Administrator is taught to us on linux), and our HOD is a linux freak. So you can guess.

Will try GDB for sure.

Damn Lucky man!! It feels gr8!! when we heard that there are atleast some colleges in India where gcc is used and specially in Linux.
 
OP
tkin

tkin

Back to school!!
[offtopic]
I can see my post got deleted. I posted it because that link did have a sample program. Op had to scroll to the bottom to see the post. No need of sign-up.
Nevermind. Seems he doesn't need any help from me.
All the best buddy. :)
[/offtopic]
And you apparently didn't see the huge banner that said sign up to view answer, also the program is not what I needed at all, too complicated, the code wiki link has the proper version that I need, thanks for your helps guys.
 
@ tkin

you are 1 lucky fella
at least you are not fed some crappy knowledge that our teachers told us on that turbo c.

what was the end result ?
in 4th yr when we had to do distributed systems and thread programming, my class fellows came to me and my frnd to tell them how to install linux and use it
 
Top Bottom