B
BartC
I'd been looking for a standalone Windows (7) executable to monitor a serial
port, but thought I'd try the following code, and it worked!
This is not exactly a C problem but perhaps someone might know why fgetc()
mostly returns -1 (EOF), presumably when no character is ready, rather than
wait until one is available (as it might do for f==stdin). As it is, it ties
up the processor, so can't be used seriously.
#include <stdio.h>
#include <stdlib.h>
int main (void) {
FILE* f;
int c;
f=fopen("com3","r");
if (!f) exit(0);
while (1) {
c=fgetc(f);
if (c!=EOF) printf("%c",c);
}
}
port, but thought I'd try the following code, and it worked!
This is not exactly a C problem but perhaps someone might know why fgetc()
mostly returns -1 (EOF), presumably when no character is ready, rather than
wait until one is available (as it might do for f==stdin). As it is, it ties
up the processor, so can't be used seriously.
#include <stdio.h>
#include <stdlib.h>
int main (void) {
FILE* f;
int c;
f=fopen("com3","r");
if (!f) exit(0);
while (1) {
c=fgetc(f);
if (c!=EOF) printf("%c",c);
}
}