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

How to transfer a large file into an array whose size is unknown

I am new to C programming and would appreciate if anyone could provide assistance. I have a large text file which i want to store in an array. But the problem is I do not know the size of the text file and subsequently the size of the array. I have tried using dynamic memory allocation but it doesnt seem to work.
Arpan
Oct 10 '10 #1
3 1583
weaknessforcats
9,208 Expert Mod 8TB
Open the file and do a seek to the end. Then do a tell.

The result of the tell will be the number of bytes in the file.

If you know the format of the file and you know the number of bytes in the file, then you know the number of array elements. From there you can allocate an array of the correct size.
Oct 10 '10 #2
Hey thanks a lot... i hav another question. This txt file has four columns of data which i would like to tranfer to four different arrays. Can i use fgets to read one line at a time and cut and append those four columns?
Oct 10 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
There should be no reason you can't do that.

I might suggest you use a struct as your array element and fill the struct members rather than use seprarate arrays.
Oct 10 '10 #4

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

Similar topics

2
by: ohaya | last post by:
Hi, I'm a real newbie, but have been asked to try to fix a problem in one of our JSP pages that is suppose to read in a text file and display it. From my testing thus far, it appears this page...
6
by: guillaume | last post by:
I have to read and process a large ASCII file containing a mesh : a list of points and triangles. The file is 100 MBytes. I first tried to do it in memory but I think I am running out of memory...
9
by: matthurne | last post by:
I need to send just an array to a function which then needs to go through each element in the array. I tried using sizeof(array) / sizeof(array) but since the array is passed into the function,...
1
by: David | last post by:
Hello. I can't upload large file with HtmlInputFile control:( Is there any file size limitation in HtmlInputFile control? If yes how can I upload to server large size file? Than you.
14
by: mohammad.nabil.h | last post by:
hello, it's me again. i was implementing a DBMS, as usual, where i needed to call fwrite using 8-byte integer as the length of the data to be written ( just in case there is data bigger than 2 GB,...
1
by: frank grimes | last post by:
I'm trying to transfer a large file (20mb) from another site to mine. Although it does transfer, the browser doesn't update. I've changed the timeout values in both IE and Firefox, but no luck. ...
6
by: half.italian | last post by:
Hi all, I'm using ftplib to transfer large files to remote sites. The process seems to work perfectly with small files, but when the file gets to large ~20GB I begin getting errors that...
1
by: minhchieu | last post by:
Hi everyone, I'm working with webservice on Net 2.0. I have a mysql database whose size is about 200MB. I want to make a copy of this database and send it to client through webservice in XML format....
2
by: thirunavukarasukm | last post by:
Hai I am creating one web application i am using xml String with one containing xml Output to assign that temporary variable.. this my requirement I want to transfer one xml file to...
2
by: kashifjawed | last post by:
I'm developing a c# asynchronous socket application for tranfering file or large data from client to server and server to client as well in chunks. Application sometimes transfer file from client...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.