473,395 Members | 1,941 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,395 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 9372
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. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...
0
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,...

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.