473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

binary file length

i have creating abinary file but iwant to know how to calculate/know the file length because ihad error when i used filelength(f1 )for example?please help me
Nov 3 '06 #1
1 9834
horace1
1,510 Expert 1GB
i have creating abinary file but iwant to know how to calculate/know the file length because ihad error when i used filelength(f1 )for example?please help me
you can get the file length from the file status, e.g.
Expand|Select|Wrap|Line Numbers
  1. // read file status, print size, dates etc
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. int main()
  7. {
  8. struct stat file_stat;
  9. int         status;
  10. char filename[50]={0};
  11. printf("enter filename ? ");
  12. scanf("%s", filename);
  13. int fildes = open(filename, O_RDWR);             // open file
  14.  
  15. // get file status for details see
  16. // http://www.opengroup.org/onlinepubs/007908799/xsh/fstat.html
  17. status = fstat(fildes, &file_stat);                 // get its status
  18.  
  19. // print file status informations for details see
  20. //   http://www.opengroup.org/onlinepubs/007908799/xsh/sysstat.h.html
  21. printf("file %s size %d\n", filename, file_stat.st_size);        // print status
  22. printf("last access %s\n", ctime(&file_stat.st_atime));
  23. printf("last mofification %s\n", ctime(&file_stat.st_mtime));
  24. printf("last status change %s\n", ctime(&file_stat.st_ctime));
  25. return 0;
  26. }
  27.  
  28.  
Nov 5 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: nightflyer | last post by:
Hi all, [code snippet appended at the end.) my question: A class has a few string variables with not know length at design time. Now I declare lets say a 1000 of those classes and put them...
6
by: Fredrik | last post by:
How can I download a binary file (like .doc or .pdf) from http to my harddrive using the .net framework? WebRequest objRequest = System.Net.HttpWebRequest.Create(url); objResponse =...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
2
by: gauravkhanna | last post by:
Hi All I need some help for the below problem: Scenario We need to send large binary files (audio file of about 10 MB or so) from the client machine (.Net Windows based application, located...
6
by: SandyMan | last post by:
Hi, I am able to open a binary file for reading but can someone tell me as how to go about converting a Binary file to ASCII file using C. Thanks In Advance SandyMan
6
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
3
by: mouac01 | last post by:
Newbie here. How do I do a find and replace in a binary file? I need to read in a binary file then replace a string "ABC" with another string "XYZ" then write to a new file. Find string is the...
8
by: Bryan.Fodness | last post by:
Hello, I am having trouble writing the code to read a binary string. I would like to extract the values for use in a calculation. Any help would be great. Here is my function that takes in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.