problems with pointers (i think)
From: Darren (foo.bar_at_world.com)
Date: 10/26/03
- Next message: Gutek: "[WinAPI] WM_CHAR & DialogBox"
- Previous message: Rob Williscroft: "Re: How can underflow, overflow be tested for using C++?"
- Next in thread: Victor Bazarov: "Re: problems with pointers (i think)"
- Reply: Victor Bazarov: "Re: problems with pointers (i think)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 26 Oct 2003 12:31:27 -0000
hi,
i'm trying to write some code to generate seperate files with the name of a
call number, and containing the call data, from one big file containing all
data.
but when i run it, i get the individual files created, but just containing
"NOTF: 206791552" and not the data. the right call number is inside the
corresponding file, just no data. i am at a loss - please help!
each call terminiates with a '~'.
#include <iostream>
#include <fstream>
using namespace std;
int main ()
{
int length;
char * buffer;
char call_num[12];
char fname[13];
int i = 0;
int j = 0;
int k = 0;
int l = 0;
ifstream inputfile ("data.txt");
if (! inputfile.is_open())
{ cout << "Error opening file: data.txt does not exist."; exit (1); }
// get length of file:
inputfile.seekg (0, ios::end);
length = inputfile.tellg();
inputfile.seekg (0, ios::beg);
// allocate memory:
buffer = new char [length];
// read data as a block:
inputfile.read (buffer,length);
inputfile.close();
for (i=0; i < length; i++)
{
if ( (*(buffer+i)=='N') && (*(buffer+(i+1))=='O') &&
(*(buffer+(i+2))=='T') && (*(buffer+(i+3))=='F') )
{
for (k=0; k < 9; k++)
{
call_num[k] = (* (buffer+ (i+(6+k)) ) );
l++;
}
call_num[9] = '.';
call_num[10] = 't';
call_num[11] = 'x';
call_num[12] = 't';
sprintf( fname, call_num);
ofstream outFile (fname);
while (*(buffer+(i+1)) != '~')
{
outFile << buffer[i];
i++;
}
cout << "Creating file: ";
cout.write (call_num,13);
cout << endl;
j++;
}
}
cout << endl << "Total number of files created = " << j << endl;
return 0;
}
- Next message: Gutek: "[WinAPI] WM_CHAR & DialogBox"
- Previous message: Rob Williscroft: "Re: How can underflow, overflow be tested for using C++?"
- Next in thread: Victor Bazarov: "Re: problems with pointers (i think)"
- Reply: Victor Bazarov: "Re: problems with pointers (i think)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|