I am trying to create a C base of code using emscripten and it goes through an abstraction layer for all of its I / O calls. This does not do what I would expect, so I tried a simpler test using here in StackOverflow:
#include <stdio.h> #include <stdlib.h> // From: /questions/63683/how-to-read-a-line-from-the-console-in-c/437628#437628 char * getline_litb(void) { char * line = malloc(100), * linep = line; size_t lenmax = 100, len = lenmax; int c; if(line == NULL) return NULL; for(;;) { c = fgetc(stdin); if(c == EOF) break; if(--len == 0) { len = lenmax; char * linen = realloc(linep, lenmax *= 2); if(linen == NULL) { free(linep); return NULL; } line = linen + (line - linep); linep = linen; } if((*line++ = c) == '\n') break; } *line = '\0'; return linep; } int main() { puts(getline_litb()); return 0; }
Compiled under gcc or clang this works great. It reads the line until you press enter and return that line. But when I compile it with:
emcc test.c -o test.bc emcc test.bc -o test.js node test.js
He thinks a line feed has been entered, so he prints an empty line and does not give me input options. Any ideas?
source share