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

how exclude initial part of a buffer???

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!!

Jan 10 '06 #1
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...

Jan 10 '06 #2
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

Jan 10 '06 #3

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-

Jan 10 '06 #4
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!!

Jan 11 '06 #5
What is the problem that you encounter?

Jan 11 '06 #6
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???

Jan 11 '06 #7
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

Jan 11 '06 #8
Thanks for all!!!!
I found the problem and made a correct.

Jan 13 '06 #9

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

Similar topics

5
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 =...
15
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...
6
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...
4
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...
7
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...
2
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...
1
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...
6
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...
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
Oralloy
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,...
0
jinu1996
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...
1
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...
0
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.