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;

( ≖‿≖)

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