Hello!
I have to take a file and exclude the inicial part (88 positions) to a
buffer.
I try with this code, but not functioning:
fp = fopen(file,"rb");
fseek(fp,0,SEEK_END);
size = ftell(fp);
data = malloc(size);
fseek(fp,88,SEEK_SET);
fread(data,size,1,fp);
fclose(fp);
Where data containg the file without 88 initial positions....
Thanks for help!! 8 1610
Sorry by this messagem. I can´t edit the first topic.
I forgott to say: The file mentioned above is a binnary file.
Tks...
fp = fopen(file,"rb");
fseek(fp,0,SEEK_END); <--I think the problem is right here, at this
instance, you move to end of the file.
size = ftell(fp);
Perhaps you can use "rewind(fp);"
data = malloc(size);
fseek(fp,88,SEEK_SET);
fread(data,size,1,fp);
fclose(fp);
Just on the side note, I didn't see any error checking for null
pointers. Perhaps you didn't mention it while posting it.
For reference you take a look at following link: http://www.cplusplus.com/ref/cstdio/fread.html
Senger wrote: Hello! I have to take a file and exclude the inicial part (88 positions) to a buffer.
I try with this code, but not functioning:
fp = fopen(file,"rb"); fseek(fp,0,SEEK_END); size = ftell(fp); data = malloc(size); fseek(fp,88,SEEK_SET); fread(data,size,1,fp);
This line is the problem. Since you are at position 88, you can only
read "size-88" bytes into 'data'.
Hope this helps,
-shez-
I tried to do something like this:
fp = fopen(file,"rb");
fseek(fp,0,SEEK_END);
size = ftell(fp);
data = malloc(size);
rewind (fp);
fseek(fp,88,SEEK_SET);
fread(data,tamanho-88,1,fp);
But not function....
Do I have another form to do that??
How I can exclude the 88 bytes from data after pass the values from
this variable??
I don't have problems when I use the iostream and fstream, like this:
ifstream file;
file.open(filename, ios::in|ios:binary|ios::ate);
size = file.tellg();
file.seekg (0, ios::beg);
file,seekg(88, ios::beg);
file.read (buffer, size);
file.close();
But I can't use the iostream or fstream. I have to use the stdio.h.
Thanks for help!!
What is the problem that you encounter?
I using the script to use a modified file.
But I have to exclude 88 bytes of the begining from file on my system.
In second mode, using a ifstream, I don't find any problems.
But when I use the first script (stdio) the values passed to buffer is
the complete file, and not the partial file, without 88 first bytes.
If I set the position of pointer using "fseek(fp,88,SEEK_SET);"
the "fread(data,1,size,fp)" it would not have to read after the 88th
byte???
With the folloing program "try.cc" I can not reproduce your problem:
// 3456789abcdefgh
#include <cstdio>
#include <cstdlib>
const char* const file = "try.cc";
const long offset = 8;
int main()
{
FILE* fp = fopen("try.cc", "rb");
fseeko(fp, 0, SEEK_END);
long size = ftell(fp);
char* data = (char*)malloc(size);
fseek(fp, offset, SEEK_SET);
fread(data, 1, size-offset, fp);
printf("%c\n", data[0]);
}
Running the program yields "8" as excepted.
You should check the return value of all called functions
to track down the problem.
Regards, Stephan
Thanks for all!!!!
I found the problem and made a correct. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Leif K-Brooks |
last post by:
When StringIO gets an initial value passed to its constructor, it seems
to discard it after the first call to .write(). For instance:
>>> from StringIO import StringIO
>>> buffer =...
|
by: could ildg |
last post by:
In re, the punctuation "^" can exclude a single character, but I want
to exclude a whole word now. for example I have a string "hi, how are
you. hello", I want to extract all the part before the...
|
by: dreamerbin |
last post by:
Hi,
I'm having trouble extracting substrings using regular expression. Here
is my problem:
Want to find the substring that is immediately before a given
substring. For example: from
"00...
|
by: Brad |
last post by:
I'm not one to rant or flame....so please excuse me while I do so for this
once. I've now spent a bit of time working with VS2005 beta 2 to see how it
functions for web development, especially how...
|
by: CuriousGeorge |
last post by:
I'm using aspnet_compiler to precompile my web app for deployment.
Currently it copies all subfolders from the asp.net projects source folder
to my destination folder. I have some files I do not...
|
by: Arsen V. |
last post by:
Hi,
How to exclude the App_Data directory from Visual SourceSafe?
It appears that Vs 2005 automatically adds the App_Data directory with the
large binary MDF and LOG files to the Visual...
|
by: AntiChrist |
last post by:
In VS 2005 if you exclude files from a project, it actually renames the
file to filename.exclude. In previous versions, it just left the file
alone but excluded it. If you have a very large...
|
by: homevista |
last post by:
PART III: Putting things together
In part I we examined the modem to verify that it supported voice. If so, we took a note about the voice data format that we would use. In the second part, we...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |