Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

binary files in c++

Name: Anonymous 2009-09-18 19:01

Please help me debug my program. It's supposed to ask the user for a number and a filename. And all it does is append that number to the file. What am I doing wrong?


#include <iostream>
#include <fstream>
using namespace std;

#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])

void append_to_file(char * FILENAME, char * B)
{
    ofstream f(FILENAME, ios::app | ios::binary);

    if (ARRAY_SIZE(B) == 4)
    {
        int *q = (int*)B;
        puts("WRITING");
        cout << " " << q;
        puts(" to ");
        cout << FILENAME;
        }
    else if (ARRAY_SIZE(B) < 0)
    {
        if (ARRAY_SIZE(B) != !1)
        {
            cout << "INVALID INPUT";
            exit(1);
            }
        }

    f.write((char*)B, sizeof(B));
    f.seekp(0, ios::beg);
    }

int main(int ARGUMENT_COUNT, char *ARGUMENTS)
{
    int x = 0;

    puts("PLEASE ENTER A NUMBER\n");
    int y;
    cin >> y;

    string d;
    puts("PLEASE ENTER A FILENAME");
    cin >> d;
    append_to_file(const_cast<char*>(d.c_str()), (char*)&y);

    return x;
    }

Name: Anonymous 2009-09-18 19:10

puts("WRITING");
cout << " " << q;
puts(" to ");
cout << FILENAME;

( ≖‿≖)

Name: Anonymous 2009-09-18 19:26

It's a god-awful small affair.

Name: Anonymous 2009-09-18 20:41

>>2
Genuinely laughed out loud.

I may HBT but I feel kind of good about it :)

Name: Anonymous 2009-09-18 20:46

the sepples, it burns my eyes.

Name: Anonymous 2009-09-18 22:24

>>5
Seconded. I would sage but this is one of the few threads on the front page that doesn't have the naked, yet curiously still stripping, coeds.

Name: Anonymous 2009-09-19 0:57

I think it's cute... You know how when kids try to draw and it ends up just being scribbles? That kind of cute.

Name: ​​​​​​​​​​ 2010-10-26 7:29

Name: Anonymous 2010-11-28 16:03

Name: Anonymous 2011-01-31 20:30

<-- check em dubz

Name: Anonymous 2011-02-03 0:01

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List