Click here to Skip to main content
16,004,806 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to sample a file using VC++? Pin
David Crow20-May-03 5:32
David Crow20-May-03 5:32 
GeneralRe: How to sample a file using VC++? Pin
flora_k20-May-03 21:25
flora_k20-May-03 21:25 
AnswerRe: How to sample a file using VC++? Pin
Trollslayer20-May-03 7:00
mentorTrollslayer20-May-03 7:00 
AnswerRe: How to sample a file using VC++? Pin
peterchen20-May-03 12:50
peterchen20-May-03 12:50 
GeneralRe: How to sample a file using VC++? Pin
flora_k20-May-03 21:40
flora_k20-May-03 21:40 
AnswerRe: How to sample a file using VC++? Pin
Andrew Walker20-May-03 16:59
Andrew Walker20-May-03 16:59 
GeneralRe: How to sample a file using VC++? Pin
flora_k20-May-03 22:48
flora_k20-May-03 22:48 
GeneralRe: How to sample a file using VC++? Pin
Andrew Walker21-May-03 2:49
Andrew Walker21-May-03 2:49 
flora_k wrote:
How does this piece of code works?

Simple idea really
1/ read enough data out of the file to rebuild one number
2/ convert that data into a number

Why like this? There are simpler ways, and this isn't safe, in fact its downright ugly, but it's extensible for big endian data.

BTW, this is C++ code. sorry missed that Frown | :( on the first readthrough, you'll probably need to use fopen and fclose to do the file management in C, and the cast to a C-Style cast. Below is a fuller example, might help if you can see it in context

#include <fstream>
#include <iostream>

using namespace std;

/**
 * Reads a buffer from an input stream
 */
double readDouble(istream& is)
{
    // Allocates a raw buffer big enough to store a single floating point number
    char buffer[sizeof(double)];
    // Reads the sizeof(double) bytes from the file
    is.read(buffer,sizeof(double));
    // Converts the buffer to a pointer to a double, then to a double
    return (double)(*(reinterpret_cast<double*>(buffer)));
}

int main()
{
    // Open file, as read only, binary
    ifstream fin("your_filename_here.bin",ios::in|ios::binary);

    double data;
    int numPoints = 1000;
    for(int i = 0; i < numPoints; ++i)
    {
        // read a number from the file
        data = readDouble(fin);
        cout << data << endl;
    }
    return 0;
}

GeneralPhysical Memory reading Pin
Muhammad Ahmed20-May-03 2:48
Muhammad Ahmed20-May-03 2:48 
GeneralRe: Physical Memory reading Pin
David Crow20-May-03 4:31
David Crow20-May-03 4:31 
GeneralRe: Physical Memory reading Pin
Daniel Turini20-May-03 12:20
Daniel Turini20-May-03 12:20 
GeneralRe: Physical Memory reading Pin
Baris Kurtlutepe20-May-03 13:22
Baris Kurtlutepe20-May-03 13:22 
GeneralInterfacing with EPABX Pin
Tushar Bhatt20-May-03 2:06
Tushar Bhatt20-May-03 2:06 
GeneralSGI STL in VS2003 Pin
Mathias S.20-May-03 1:55
Mathias S.20-May-03 1:55 
GeneralLooking for Good, Concise C++ Tutorials Pin
Kevin McFarlane20-May-03 1:24
Kevin McFarlane20-May-03 1:24 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
AlexO20-May-03 4:26
AlexO20-May-03 4:26 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Kevin McFarlane20-May-03 5:27
Kevin McFarlane20-May-03 5:27 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
AlexO20-May-03 5:38
AlexO20-May-03 5:38 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Daniel Turini20-May-03 9:01
Daniel Turini20-May-03 9:01 
GeneralRe: Looking for Good, Concise C++ Tutorials Pin
Kevin McFarlane20-May-03 11:41
Kevin McFarlane20-May-03 11:41 
QuestionHow to disable task menu item? Pin
no_body6920-May-03 1:16
no_body6920-May-03 1:16 
AnswerRe: How to disable task menu item? Pin
Rickard Andersson2020-May-03 3:29
Rickard Andersson2020-May-03 3:29 
GeneralRe: How to disable task menu item? Pin
Rickard Andersson2020-May-03 3:30
Rickard Andersson2020-May-03 3:30 
GeneralRe: How to disable task menu item? Pin
no_body694-Jun-03 23:53
no_body694-Jun-03 23:53 
GeneralSOCKET &amp; BROADCAST Pin
borini19-May-03 23:50
borini19-May-03 23:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.