fread - what am I doing wrong

This is a discussion on fread - what am I doing wrong within the C++ Programming forums, part of the General Programming Boards category; I'm supposed read the content of a file, trim its content and copy the trimed content to a secundary file.... ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    47

    fread - what am I doing wrong

    I'm supposed read the content of a file, trim its content and copy the trimed content to a secundary file.... somehow, it's not working like it was supposed to .... any idea ????

    PHP Code:
    if( (Buffer=fopen(m_Source_File"r" )) == NULL )
        
    MessageBox("Source File Not Found");
    else
      {
      
    freadSource_Textsizeofchar ),2048Buffer );
      
    pdest strstr(Source_Text,"ISUP MESSAGE MONITOR RESULT");
      
    Text_Trim_Begin pdest Source_Text;
      
    pdest strstr(Source_Text,"END ");
      
    Text_Trim_End pdest Source_Text +3;
      for(
    int i=Text_Trim_Begina=0i<Text_Trim_End;i++, a++)
        {
        
    Source_Text[a]=Source_Text[i];
        }
      
      if( (
    Buffer =fopen(m_Destination_File"w+" )) == NULL )
          
    MessageBox("Destination File Not Found");
      
    int space Text_Trim_Begin Text_Trim_End 1;
      
    fwrite(pTitle_1,   sizeof(char), 82  Buffer);
      
    fwrite(pTitle_2,   sizeof(char), 82  Buffer);
      
    fwrite(Source_Text,sizeof(char), Text_Trim_EndBuffer);     // I belive the error is in this line .... not shure
      
    fwrite(pTitle_3,   sizeof(char), 82  Buffer);
      
    fclose(Buffer);

    I'm a person with a simple taste...
    I only like the best.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,588
    Well if its a text file, stick to fgets() and fputs()

    Oh, and stick to code tags, not php tags

    > fread( Source_Text, sizeof( char ),2048, Buffer );
    This does NOT append a \0 to the data read
    > pdest = strstr(Source_Text,"ISUP MESSAGE MONITOR RESULT");
    This needs a \0 to work properly
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why is fread sometimes taking so long?
    By manugarciac in forum C++ Programming
    Replies: 2
    Last Post: 04-28-2007, 11:25 PM
  2. return value of fread()
    By m.mixon in forum C Programming
    Replies: 5
    Last Post: 07-24-2006, 06:31 PM
  3. Reasons as to why fread would fail
    By Happy_Reaper in forum C Programming
    Replies: 4
    Last Post: 04-08-2006, 11:41 AM
  4. fread item_size limit
    By nvoigt in forum C++ Programming
    Replies: 2
    Last Post: 03-30-2005, 08:08 AM
  5. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21