problems with pointers (i think)

From: Darren (foo.bar_at_world.com)
Date: 10/26/03


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;
}



Relevant Pages

  • Re: Performance hit
    ... WITH FILLFACTOR = 90 ON ... > Before splitting the Non clusteredd Index and data into seperate files try ... > remove the fragmentation by DBCC DBREINDEX ...
    (microsoft.public.sqlserver.server)
  • Is this necessary?
    ... I am reading K&R The C Programming Language. ... int getop; ... void push; ... The 3 first function are implemented in seperate files but is it strictly ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Two threads read from one file?
    ... are you sure that your problems are not related to rendering of data ... int createFile(char* fname) ... > I need each thread to have its own file seek pointer, ...
    (microsoft.public.dotnet.languages.vc)
  • Re: PCI Driver
    ... > Could I access the custom PCI card without a device driver? ... extern int PCI_ERR; ... char *FindDevice(unsigned short VendorID, ... int Write_PCI_Config_Word(char *fname, ...
    (comp.os.linux.development.system)
  • Re: [RFC][PATCH] Fix hang in posix_locks_deadlock()
    ... const char *fname = NULL; ... // release the gross lock before attempting the fcntl ... int main ... pid_t mypid = fork; ...
    (Linux-Kernel)