Thread: Binary files

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    207
    Hmm... I seem to have more questions:

    Code:
    #include <stdio.h>
    
    //prototypes
    int start_binary (void);
    void scope_test (void);
    
    int main (void)
    {
        start_binary ();
    
        return (0);
    }
    
    int start_binary (void)
    {
        char x[10] = "ABCDEFGHIJ";
        FILE *fp = fopen ("prime_binary.txt", "wb");
    
        if (!fp)
        {
            printf ("\n\nERROR!  Not enough memory!\n\n");
    
            return (0);
        }
    
        fwrite (x, sizeof (x[0]), sizeof (x) / sizeof (x[0]), fp);
    
        scope_test ();
    
        fclose (fp);
        printf ("\n\n");
        return (0);
    }
    
    void scope_test (void)
    {
        int loop = 0;
        char x[10] = "JIHGFEDCBA";
    
        FILE *fp = fopen ("prime_binary.txt", "a");
    
        for (loop = 0; loop < 10; loop++)
        {
            fprintf (fp, "%c", x[loop]);
        }
    
        fclose (fp);
    }
    (If there are any syntax errors, I apologize. I'm on a seperate computer and had to retype it here)

    When I run this program:

    1) Why doesn't Windows crash when I attempt to open a file twice (especially in different modes)?

    2) Why do I only have 1 line instead of 2 in my text file after this program is finished running? I was trying to "append" in my scope_test function to see what would happen.

    Thanks!

    mw
    Last edited by Lionmane; 08-23-2005 at 12:38 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  2. send/recv binary files using sockets in C++
    By dafatdude in forum Networking/Device Communication
    Replies: 14
    Last Post: 07-25-2004, 11:00 AM
  3. MFC: CStrings & binary files question(s)
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-24-2004, 05:41 PM
  4. Binary files
    By Brian in forum C Programming
    Replies: 2
    Last Post: 02-18-2002, 01:13 PM
  5. storing string objects to binary files
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-06-2001, 11:33 PM