Thread: Problem Writing to Text File

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    49

    Question Problem Writing to Text File

    For all list_count entries, I would like to print out e_list to a text file. However, I receive the error: "warning C4133: 'function' : incompatible types - from 'struct _iobuf *' to 'const char *"

    Looking at the documentation for the error, I'm not sure how to rectify the problem. Help is greatly appreciated.

    Code:
    static int list_count;
    
    static struct e_list_entry
    {
       signed int delta : 8;
       signed int xy : 24;
       signed int type : 8;
       signed int c : 24;
       struct e_list_entry *link;
    } e_list[1000];
    
    static void sort_horiz(void)
    {
       int i;
       int dx, dy, d;
       FILE *file;
    
       file=fopen("C:\\myfile_c.txt", "w");
    
       for (i = 0; i < list_count; i++)
       {
          dx = e_list[i].c - (ia_nx >> 1);
          dy = e_list[i].xy - (ia_ny >> 1);
    
          if(file)
          {
             printf(file, "%d", e_list);  /* error */
             fclose(file);
          }
       }   
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It should be fprintf() if you want to write to a file.

    And why are you closing it immediately after writing to it once?

    To make the code safe, you need to follow the fclose() with
    file = NULL;
    to protect the code the next time around the loop.
    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.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    49
    Ah, such stupid mistakes! I wasn't paying close enough attention to what I was doing. Thank you Salem!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Problem viewing text file
    By JamMan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2001, 07:32 AM