hallo,
für einen kleinen chat habe ich folgenden code geschrieben. allerdings wird in der main function das fgets nicht ausgeführt (getchar & scanf genauso wenig). hat jmd einen hinweis? das 2. programm realisiert das senden und funktioniert fehlerfrei.
ich verwende TC2.01 unter Win98
Code:
#include <stdio.h>
#define FALSE 0
#define TRUE !FALSE
#define SYN 22
#define NUL 0
#define DELAY 20
#define PORT 768
#define BUFFER_LEN 1024
int idx;
char buffer[BUFFER_LEN] = "";
/* Dummys */
char inportb() {char c;scanf("%c", &c);return c;}
void outportb(int port, char c) {printf("%c ", c);}
void delay() {}
void write() {
idx = 0;
do {
outportb(PORT, SYN);
delay(DELAY);
outportb(PORT, buffer[idx]);
delay(DELAY);
} while (buffer[idx] != NUL && ++idx);
}
char read_char() {
char in;
int syn_found = FALSE;
while (TRUE) {
if ((in = inportb(PORT)) == SYN) {
syn_found = TRUE;
continue;
}
if (syn_found) {
buffer[idx++] = in;
return in;
}
}
}
void read() {
idx = 0;
while (read_char() != NUL)
;
}
int main() {
int is_sender = TRUE;
while (TRUE) {
if (is_sender) {
printf("write:\n");
fgets(buffer, BUFFER_LEN, stdin); /* <-- Hier ist der Fehler /////////////////////////////////*/
write();
buffer[0] = NUL;
is_sender = !is_sender;
}
else {
printf("read:\n");
read();
printf("%s\n", buffer);
buffer[0] = NUL;
is_sender = !is_sender;
}
}
}
Code:
#include <stdio.h>
#define FALSE 0
#define TRUE !FALSE
#define SYN 22
#define NUL 0
#define DELAY 20
#define PORT 768
#define BUFFER_LEN 1024
int idx;
char buffer[BUFFER_LEN] = "";
char inportb() {char c;scanf("%c", &c);return c;}
void outportb(int port, char c) {printf("%c ", c);}
void delay() {}
void write() {
idx = 0;
do {
outportb(PORT, SYN);
delay(DELAY);
outportb(PORT, buffer[idx]);
delay(DELAY);
} while (buffer[idx] != NUL && ++idx);
}
int main() {
printf("write:\n");
fgets(buffer, BUFFER_LEN, stdin);
write();
buffer[0] = NUL;
return 0;
}