Jump to content
  • 0

CC65 and file i/o


Sandmage
 Share

Question

I'm toying around with cc65. I'm trying to write a string to a file and read it back again.
The following example works on a C64, yet x16emu cannot open the file for writing. Even with an sdcard attached.

Does anyone know whether this is unimplemented or a bug? The source in cc65/libsrc/common for fopen seems to be common among all "cbm" machines.

#include <stdlib.h>
#include <stdio.h>

char buf[128];

int main(void) {
    
    FILE *fp;
    int i;
    for (i = 0; i < 128; ++i) {
        buf = '\0';
    }
    fp = fopen("testfile", "wb");
    if (fp == NULL) {
        printf("Could not open file for writing.");
        return 0;
    }
    fputs("Hello World in text", fp);
    fclose(fp);

    fp = fopen("testfile", "rb");
    if (fp == NULL) {
        printf("Could not open file for reading.");
        return 0;
    }

    fgets(buf, 128, fp);
    fclose(fp);

    printf("%s\n", buf);
    return 0;
}

 

Edited by Sandmage
  • Like 1
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use