Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-01-2005, 12:20 AM   #1
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 9.2
Posts: 1,208

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, 01:17 AM   #2
Senior Member
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

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

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, 09:22 AM   #3
LQ Guru
Registered: Jan 2001
Posts: 24,149

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

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


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 06:54 PM
Cannot stat??? chui_yap Linux - Newbie 1 01-04-2005 07:56 PM
cannot stat scottsteibel Linux - Newbie 2 12-11-2004 04:51 PM
stat warney_out Programming 1 09-28-2004 04:37 AM
Linux stat to Windows Stat sridurai Programming 3 09-24-2004 05:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration