473,799 Members | 3,026 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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,SEE K_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 1624
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,SEE K_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,SEE K_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,SEE K_SET);
fread(data,tama nho-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(filen ame, ios::in|ios:bin ary|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,SE EK_SET);"
the "fread(data,1,s ize,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(s ize);
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
2863
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 = StringIO('foo') >>> buffer.getvalue() 'foo' >>> buffer.write('bar') >>> buffer.getvalue() 'bar'
15
17912
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 world "hello", I can't use ".*" because "^" only exclude single char "h" or "e" or "l" or "o". Will somebody tell me how to do it? Thanks.
6
2438
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 noise1 01 noise2 00 target 01 target_mark", want to get "00 target 01"
4
2892
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 our current extensive number of .Net 1.1 web apps convert to it. After a week's time I dont's mind the converted app code that was broken and had to be changed, due to deprecation, new framework classes (some of which have names identical to...
7
6361
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 want it to copy when deploying this app, is there any way to exclude them? I like to keep all files related to my projects within that projects folder hierarchy (such as schemas, documentation, etc), but I don't want them deployed, or to have to...
2
1961
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 SourceSafe. Is there a way to prevent this from happening? Thanks,
1
1592
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 ASP.net web site you may have thousands of images. In our case we have millions because the nature of the site is that users upload their photo albums to share with other users. I NEVER want the IDE to enumerate these files for any reason, including...
6
29159
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 prepared a wave file and implemented a piece of code in C# to be used by HomeZIX to read the wave file into a buffer. Now, it’s time to put things together to send out that buffer as an audio stream over the phone line to a designated phone number. ...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10031
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7571
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.