Reading serial data from the Arduino in C

I'm trying to read serial data printed by the Arduino with this C program -

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

int main (int argc, char *args []) {

    char test;
    FILE *serialPort;

    system( "MODE COM4: BAUD=9600 PARITY=n DATA=8 STOP=1" );
    serialPort = fopen("COM4:", "r" );

    if (serialPort == NULL) {
        printf ("Error: unable to open serial port COM4\n");
        exit (1);
    }

    while (1) {
        test = fgetc (serialPort);
        if (test == EOF) {
            printf ("End of file\n");
            break;
        }
        printf ("%c", test);
    }

    fclose(serialPort) ;

    return 0;
}

The problem is that it just stops when it gets to the fgetc line. It doesn't quit or anything, it just sits there with a blinking cursor. Is that because of an error with the code on my Arduino (it's just looping over 'Serial.print ("x");' over and over again), or is this method of reading data just not going to work?

Thanks very much!

have you checked the examples here - http://www.arduino.cc/playground/Main/InterfacingWithSoftware

Yeah, the example for interfacing in C doesn't seem to compile in Windows though - I might take another go at it if I have time, but I wasn't really planning on spending too much time trying to get this to work.

Thanks for replying :slight_smile: