I have this code. what I want to do is to wait for user to press 'q' to end the program.

```
.
...starting few threads, which use fflush(stdout) (just saying...)
.
char n = 0;
while (n != 'q') {
    n = getchar(); //tried to use scanf() here as well
    printf("%c", n);
}
...killing all threads...
return 0;

```

When I run this **in a normal Linux enviroment it works fine.**
The problem starts when I run this program at startup on my raspberry-pi with debian jessie lite distribution (I added the path to the program to /etc/rc.local) - it ends in an infinite loop, `scanf` is still returning `-1` and `getchar()` some weird character and the program won't end, when I press `q`. Ctrl+C doesn't work either so there is no way, how to end the program.
Any suggestions? (at least how to kill the program...?)

Edit: To let you know what the program does.
Raspberry-pi with this program is attached to some serial ports and converts and transfers some GPS data. It should work "out of the box" without any keyboard or mouse or monitor. = **Just plug the device to some cables and do nothing more.** In some cases someone would like to see log files on the raspberry, so he needs to stop the program, obviously.

Edit2: when I did the same with some normal Raspbian, it worked fine too.

**Update:**

I tried to debug it - shrinked the code to this only

```
int main(void){
    char n=0;
    int x;
    while (n != 'q'){
        clearerr(stdin);
        x=scanf("%c",&n);
        printf("%c %d\n",n,x);
    }
    return 0;
}

```

added `service start udev` to rc.local and tried command `update.rc.d udev enable`

output on raspberry-pi when launched at startup is still

```
-1
-1
-1
.
.

```

so there definitely have to be something wrong with stdin.
After startup and on other systems, the output is obviously `q 1` (when I press 'q' (and enter) ...)

when I tried to read from `/dev/tty`, `fopen()` returned `NULL`

Really need a help with this