Problem Writing to Text File

This is a discussion on Problem Writing to Text File within the C Programming forums, part of the General Programming Boards category; For all list_count entries, I would like to print out e_list to a text file. However, I receive the error: ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,558
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 04:02 AM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM
  5. Problem viewing text file
    By JamMan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2001, 06:32 AM

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