473,233 Members | 3,513 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,233 software developers and data experts.

How to store the data in buffer

18
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 9337
weaknessforcats
9,208 Expert Mod 8TB
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
Couldn't make out with the work, still.
Dint understood, how to do..!
Mar 28 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
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
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....
3
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...
2
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. ...
36
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...
3
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...
5
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
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...
3
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...
0
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. ...
2
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. ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
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
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
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...

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.