473,385 Members | 1,569 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,385 software developers and data experts.

splitting a file

How can I split a file into several files each with a fixed size?
I recall that on linux there is a command that has a counter for file size
in bytes but cant seem to remember.

Help is appreciated.

Nov 15 '05 #1
2 1549
Afifov wrote:
How can I split a file into several files each with a fixed size?
I recall that on linux there is a command that has a counter for file size
in bytes but cant seem to remember.

Help is appreciated.


As this is comp.lang.c and not some Linux newsgroup, I suggest you
get the name of the file to be split, the maximum size S of the parts,
fopen() the file in binary mode and then
1) Try to fread() up to S bytes with return of R read bytes
2) Try to open the file for the next part (do you want to overwrite
or die on error?)
3) fwrite() R bytes to the current output file, close it.
4) if R<S, terminate. Else continue at 1.

fclose() your source file.
Done.

<OT>Have you tried 'man split'?</OT

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Nov 15 '05 #2
Afifov wrote:
How can I split a file into several files each with a fixed size?


All the same size? If the file size is composite, this is quite easy. If,
however, the file size is prime, the task is rather more difficult, as it
will involve splitting the byte into subytomic particles. Doable, but
requires a lot of energy.

If you are prepared for the various output files to be of various sizes,
this becomes trivial. You will need:

fopen, fread (or getc), fwrite (or putc), fclose

Curiously, if you know the largest file size you are willing to /write/,
then you almost certainly don't need to know the file size in advance.

Try writing the program. You'll probably be amazed at how simple it is. But
if you get stuck, show us your best shot.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: robsom | last post by:
Hi, I have a problem with a small python program I'm trying to write and I hope somebody may help me. I'm working on tables of this kind: CGA 1988 06 21 13 48 G500-050 D 509.62 J.. R1 1993 01...
4
by: Brice Vissi?re | last post by:
Hello, I would like to handle an XML file structured as following <ROOT> <STEP> .... </STEP> <STEP> .... </STEP>
6
by: nwheavyw8 | last post by:
I am currently trying to write a simple PHP script that will split an uploading file up into 500kb "chunks", then read and concatenate them back together when accessed for download. I can't seem...
1
by: Andy Britcliffe | last post by:
Hi I'm faced with the situation where I could have a single physical file that could contain multiplie XML documents e.g file.txt contains the following: <?xml version="1.0"...
6
by: Earl Anderson | last post by:
I have a A97/XP applet I've developed for my own use in my department. My boss "suggests" that since I built it, I share it with and instruct the other 6 members of my department on its use. I've...
1
by: CaptainWillard | last post by:
Is there any difference between splitting the .mdb vs. linking a table in another .mdb file ? For example, if I use the database splitter tool I end up with Widgets.mdb and Widgets_be.mdb. All the...
4
by: nikila | last post by:
Hi, I am trying to split large xml files to smaller xml files using c#.net. can you please provide any sample code for this? I have to split the file if the size is more than 10 MB. Also, xml...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
4
by: Steven D'Aprano | last post by:
I'm trying to split a URL into components. For example: URL = 'http://steve:secret@www.domain.com.au:82/dir" + \ 'ectory/file.html;params?query#fragment' (joining the strings above with plus...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.