473,806 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to store the data in buffer

18 New Member
Hello,

I want to read a file and to pass the values in a buffer but the values are of different datatype. So I cant put the values in the char type buffer.
What to do?

I found this but dint worked for me...
Expand|Select|Wrap|Line Numbers
  1. void print ( char *Buffer, usigned long bufferSize, int chunkSize );
  2.  
  3. /*This fn will accept file buffer and the buffer size and the chunk size
  4. Send the buffer in chunks which is provided by the parameter.
  5. */
  6.  
  7. FILE *fp23 = fopen( "c:\\file.txt", "rb" );
  8.  
  9. fseek (fp23 , 0 , SEEK_END);
  10. int m_jobSize = ftell (fp23);
  11. rewind (fp23);
  12.  
  13. char* m_buffer = new char[m_jobSize+1];
  14. int m_result = fread( m_buffer, 1, m_jobSize, fp23 );
  15. int chunkSize = 1;
  16. void print ( m_buffer, m_jobSize, chunkSize);
  17.  
  18.  
  19. void print ( char *m_buffer, usigned long m_jobSize, int chunkSize)
  20. {
  21.     int BytesIndex = 0;
  22.     while( bufsize > 0) 
  23.     {
  24.           if ( bufsize < (unsigned long)iSendStatus ) // Send some bytes
  25.           {
  26.               iSendStatus = send(*sock, &m_buffer[BytesIndex], bufsize, 0); 
  27.                                                           // Call Back Function
  28.               set += iSendStatus;
  29.               ptr(jobid,set);
  30.               if ( iSendStatus != bufsize )
  31.               {
  32.                    cpError = SocketErrorHandler();
  33.                    return cpError;
  34.               }
  35.  
  36.          }
  37.          else
  38.          {
  39.              iSendStatus = send(*sock, &m_buffer[BytesIndex], chunkSize, 0); 
  40.                                                          // Call Back Function
  41.              set += iSendStatus;
  42.              ptr(jobid,set);
  43.  
  44.              if ( iSendStatus != chunkSize )
  45.              {
  46.                  cpError = SocketErrorHandler();
  47.                  return cpError;
  48.              }
  49.  
  50.         } 
  51.                                                // Update buffer and counter
  52.        if ( bufsize < (unsigned long)iSendStatus )
  53.        {
  54.           bufsize -= bufsize;
  55.           BytesIndex += bufsize;
  56.        }
  57.       else
  58.       { 
  59.          bufsize -= iSendStatus;
  60.          BytesIndex +=iSendStatus;
  61.       }
  62. }
  63.  

Anyone can help..!
Thanks :)
Mar 20 '08 #1
3 9467
weaknessforcats
9,208 Recognized Expert Moderator Expert
fread() doesn't care what the buffer type is. That argument is a void*. Just define your buffer of the correct type and pass the address to fread().
Mar 20 '08 #2
jhamb
18 New Member
Couldn't make out with the work, still.
Dint understood, how to do..!
Mar 28 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
This is fread() prototype:
Expand|Select|Wrap|Line Numbers
  1. size_t fread( 
  2.    void *buffer,
  3.    size_t size,
  4.    size_t count,
  5.    FILE *stream 
  6. );
  7.  
To read 1000 ints you would:
Expand|Select|Wrap|Line Numbers
  1. int buffer[1000]
  2. fread(buffer, sizeof(int), 1000, myFile);
  3.  
Mar 28 '08 #4

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

Similar topics

2
1816
by: clwoods | last post by:
I would like to ask is thier a better way to store data other than access tables, I would still like to keep access as the front end. My main quest I suppose is for more speed and maybe security. your thoughts are appreciated Many Thanks Colin
3
5294
by: Forconi Boris via .NET 247 | last post by:
Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created with text, and in each row, there 's atextBox (with an incremental ID number) in witch the user canenter a number of products. When the user clicks on the "Submit"button, I must know witch row he has selected, AND WITCH NUMBERHE HAS ENTERED in the...
2
2139
by: jmensch | last post by:
Hello. I'm a reasonably new ASP.NET programmer with no prior ASP or web development experience, but a lot of general programming experience. I'm using Visual Web Developer Beta Express 2005. I'm trying to find a way to store data in the URL of my pages. I know that SessionState does this if you go cookieless, and that's useful but it's not what I want because the real data is stored on the server, and only an ID code is
36
2868
by: Crirus | last post by:
Hi I have about 1000 records of users to store.. I dont like the ideea of a database server... How to store does data in a structured way? An XML? How big can became such an xml, because I whould like to load it and search for data. Can I search for some data without loading all xml into memory? --
3
4447
by: piotrek | last post by:
Hi I would like to ask you a question. Ian creating app. that download from server directory structure ( whole tree ) and those data are placed in proper places into my treeview control. I decided that the most effective way would be : When i connect to the server once, I download the list and disconnect, instead of connecting every time i go, to the lower node in my tree hierarhy. Thus i have a problem - how to store data.
5
1406
by: res7cxbi | last post by:
hi, im familiar with xml but wondering if it would be better to store data within attributes: <root> <data value="someData"/> </root> or within nodes:
7
4089
by: TYF | last post by:
hello, im completely new to c and programming. now i need to store data from a input buffer in a struct and then sending the struct back, not the buffer, but i dont know how to start.any help would be nice. thx
3
1632
nurulshidanoni
by: nurulshidanoni | last post by:
i hava a data student id examcode 1 002 006 001 2 123 589 How to store data when it have two data in 1 foleslike above? in .txt ot .cpp?
0
1192
by: asharda | last post by:
Hello, I have written a sample async code (using callback/async). I am now seeing a situation where-in if two messages are received at the same-time, both of them show-up in the data-buffer. Given that i am new to this, can you point to resources or suggest ways to handle this scenario? (the program runs indefinitely, handling messages as they come in).
2
4885
by: creative1 | last post by:
Is this possible to store data in an XML file using HTML form? I got it working other way. I can store data in an xml file and display it in html form. I need to do it other way. It is very urgent. thanks
0
9599
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
10371
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
10374
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
10111
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...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
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
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
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.