Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 29-04-2011, 08:40 PM   #1 (permalink)
Project Halcyon V2.0
 
tkin's Avatar
 
Join Date: Aug 2008
Location: Kolkata
Posts: 6,103
Default Help with this C program!!


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?
__________________
Project Halcyon v2.0:
Spoiler:
[i7 2600k|Asus Z68 VPro|Vengeance 2x4GB|MSI GTX580 Lightning]
[TX 750v2|Seagate 500GB+WD Cav Black 1TB|CM HAF 912 Adv]
[Logitech G110|G500|Adata/750GB+WD/500GB USB 3.0]
[APC 1100VA|XBox 360 Controller|Noctua U12PSE2]
[Siberia Soundcard(Xear 3D)|Koss Portapro|FiiO E6]
[Audio Technica M35|PL30/EOL'ed]
tkin is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 29-04-2011, 11:47 PM   #2 (permalink)
Super Moderator
 
asingh's Avatar
 
Join Date: May 2008
Location: New Delhi
Posts: 5,548
Default Re: Help with this C program!!

Quote:
Originally Posted by tkin View Post
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..!
__________________
MSI P45 Platinum(BIOS v1.7B)|Q9550[E0]@3.85Ghz@1.320V[453x8.5]MCH@1.184V|ICH@1.55V|DDR_V_Ref_A_B@1.05V|NH-D14|Corsair TWIN2X4096-8500C5(5-5-5-15)@1089Mhz@2.14V
2xHD4890[Xfire]@1000/900[MEM/GPU]|Corsair 650TX|Seagate180GB+80GB+WD1TB|SONY-DVD-R|CM690|2x120mm Scythe Ultra Kaze|DELL S2409W|APC 1100VA|Scythe Kaze Server
Windows 7 Ultimate RTM - 64BIT|Catalyst 10.5 (8.14.10.0753) forced with RadeonPRO|PS3 160GB|Sony 40EX520|AC Ryan POHD Mini|APC 800VA|APC 800VA|D425KT|CM100 Elite|2TB WD|Acer D255

Test your spoiler tags before submitting
asingh is online now   Reply With Quote
Old 30-04-2011, 12:21 AM   #3 (permalink)
Project Halcyon V2.0
 
tkin's Avatar
 
Join Date: Aug 2008
Location: Kolkata
Posts: 6,103
Default Re: Help with this C program!!

Quote:
Originally Posted by asingh View Post
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.
__________________
Project Halcyon v2.0:
Spoiler:
[i7 2600k|Asus Z68 VPro|Vengeance 2x4GB|MSI GTX580 Lightning]
[TX 750v2|Seagate 500GB+WD Cav Black 1TB|CM HAF 912 Adv]
[Logitech G110|G500|Adata/750GB+WD/500GB USB 3.0]
[APC 1100VA|XBox 360 Controller|Noctua U12PSE2]
[Siberia Soundcard(Xear 3D)|Koss Portapro|FiiO E6]
[Audio Technica M35|PL30/EOL'ed]
tkin is offline   Reply With Quote
Old 30-04-2011, 12:39 AM   #4 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Help with this C program!!

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.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 30-04-2011, 01:04 AM   #5 (permalink)
Project Halcyon V2.0
 
tkin's Avatar
 
Join Date: Aug 2008
Location: Kolkata
Posts: 6,103
Default Re: Help with this C program!!

Quote:
Originally Posted by krishnandu.sarkar View Post
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.
__________________
Project Halcyon v2.0:
Spoiler:
[i7 2600k|Asus Z68 VPro|Vengeance 2x4GB|MSI GTX580 Lightning]
[TX 750v2|Seagate 500GB+WD Cav Black 1TB|CM HAF 912 Adv]
[Logitech G110|G500|Adata/750GB+WD/500GB USB 3.0]
[APC 1100VA|XBox 360 Controller|Noctua U12PSE2]
[Siberia Soundcard(Xear 3D)|Koss Portapro|FiiO E6]
[Audio Technica M35|PL30/EOL'ed]
tkin is offline   Reply With Quote
Old 30-04-2011, 01:11 AM   #6 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Help with this C program!!

Quote:
Originally Posted by tkin View Post
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
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 30-04-2011, 01:14 AM   #7 (permalink)
Project Halcyon V2.0
 
tkin's Avatar
 
Join Date: Aug 2008
Location: Kolkata
Posts: 6,103
Default Re: Help with this C program!!

Quote:
Originally Posted by krishnandu.sarkar View Post
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.
__________________
Project Halcyon v2.0:
Spoiler:
[i7 2600k|Asus Z68 VPro|Vengeance 2x4GB|MSI GTX580 Lightning]
[TX 750v2|Seagate 500GB+WD Cav Black 1TB|CM HAF 912 Adv]
[Logitech G110|G500|Adata/750GB+WD/500GB USB 3.0]
[APC 1100VA|XBox 360 Controller|Noctua U12PSE2]
[Siberia Soundcard(Xear 3D)|Koss Portapro|FiiO E6]
[Audio Technica M35|PL30/EOL'ed]
tkin is offline   Reply With Quote
Old 30-04-2011, 01:24 AM   #8 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Help with this C program!!

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.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 30-04-2011, 09:45 AM   #9 (permalink)
Simply a DIGITian
 
krishnandu.sarkar's Avatar
 
Join Date: Nov 2007
Location: Kolkata
Posts: 2,942
Default Re: Help with this C program!!

^^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.
__________________
  • Read The Forum RULES First.
  • Before PM'ing Or Asking Any Questions To Any Mod Read The FAQ's
  • Before Starting A New Thread Read The STICKY THREADS First
  • Before Participating In Bazaar Section Read The BAZAAR RULES
krishnandu.sarkar is online now   Reply With Quote
Old 30-04-2011, 11:37 AM   #10 (permalink)
Alpha Geek
 
Join Date: Jan 2007
Location: In your hearts
Posts: 828
Default Re: Help with this C program!!

Quote:
Originally Posted by tkin View Post
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.
abhijangda is online now   Reply With Quote
Old 30-04-2011, 03:54 PM   #11 (permalink)
Project Halcyon V2.0
 
tkin's Avatar
 
Join Date: Aug 2008
Location: Kolkata
Posts: 6,103
Default Re: Help with this C program!!

Quote:
Originally Posted by Garbage View Post
[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.
__________________
Project Halcyon v2.0:
Spoiler:
[i7 2600k|Asus Z68 VPro|Vengeance 2x4GB|MSI GTX580 Lightning]
[TX 750v2|Seagate 500GB+WD Cav Black 1TB|CM HAF 912 Adv]
[Logitech G110|G500|Adata/750GB+WD/500GB USB 3.0]
[APC 1100VA|XBox 360 Controller|Noctua U12PSE2]
[Siberia Soundcard(Xear 3D)|Koss Portapro|FiiO E6]
[Audio Technica M35|PL30/EOL'ed]
tkin is offline   Reply With Quote
Old 01-05-2011, 12:32 AM   #12 (permalink)
XLr8
 
arpanmukherjee1's Avatar
 
Join Date: Sep 2008
Posts: 637
Default Re: Help with this C program!!

@ 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
__________________
Quote:
There are more things in heaven and earth, Horatio,
Than are dreamt of in your philosophy.
arpanmukherjee1 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2