emscripten-core / emscripten-core/emscripten

How use fwrite in Wasm

Open
#14,203 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

In main.cpp :
`#include
#include

int main() {
FILE *fh;

fh = fopen("a.txt", "wb");
if (!fh) exit(1);
fclose(fh);

fh = fopen("a.txt", "rb");
if (!fh) exit(1);

char data[] = "foobar";
size_t written = fwrite(data, 1, sizeof(data), fh);

printf("written=%zu\n", written);
}`

And compile it as:
emcc main.c -o main.html --preload-file a.txt

finally i run the html , why the a.txt is empty, how to use the fwrite, write something to the file?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.