#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
|
|
|
class Book {
public:
char title[51];
char ISBN[16];
char price[8];
char quantity[6];
void ReadData( char*, char*, char*, char* );
};
|
|
|
void Book::ReadData( char* a, char* b, char* c, char* d ) {
fstream file;
char spaces[51] = " ";
strcpy ( title, spaces );
strncpy( title, a, strlen(a) );
strcpy ( ISBN, spaces );
strncpy( ISBN, b, strlen(b) );
strcpy ( price, spaces );
strncpy( price, c, strlen(c) );
strcpy ( quantity, spaces );
strncpy( quantity, d, strlen(d) );
file.open ( "books.txt", fstream::out|fstream::app );
file.write( title, 50 );
file << "|";
file.write( ISBN, 15 );
file << "|";
file.write( price, 7 );
file << "|";
file.write( quantity, 5 );
file << "|";
file << endl;
file.close( );
};
|
|
|
int main( int argc, char* argv[ ] ) {
char title[51], ISBN[16], price[8], quantity[6];
Book b;
strcpy( title, argv[1] );
strcpy( ISBN, argv[2] );
strcpy( price, argv[3] );
strcpy( quantity, argv[4] );
b.ReadData( title, ISBN, price, quantity );
}
|
|
|
|