LinuxQuestions.org
Visit Jeremy's Blog.
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 05-31-2005, 11:20 PM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,178

Rep: Reputation: 51
Use of stat() in C


Can anyone tell me how to use stat() in a C program.
I'd like to find the length of a file to create arrays.
Thank you for your help.
 
Old 06-01-2005, 12:17 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,289

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
I think the man page is pretty much self-explanatory here ... something like

Code:
struct stat s;
off_t file_len;

if(stat("/path/to/whatever", &s) == 0) {
  file_len = s.st_size;
} else {
  /* handle error */
}
Oh, and this probably should've been asked in the programming forum.
 
Old 06-01-2005, 08:22 AM   #3
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 256Reputation: 256Reputation: 256
Moved: More suitable in our Programming forum.
 
Old 06-02-2005, 06:41 AM   #4
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,178

Original Poster
Rep: Reputation: 51
Thank you very much.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot stat DAChristen29 Linux - Software 1 05-23-2005 05:54 PM
Cannot stat??? chui_yap Linux - Newbie 1 01-04-2005 06:56 PM
cannot stat scottsteibel Linux - Newbie 2 12-11-2004 03:51 PM
stat warney_out Programming 1 09-28-2004 03:37 AM
Linux stat to Windows Stat sridurai Programming 3 09-24-2004 04:07 PM

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

All times are GMT -5. The time now is 09:29 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration