#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#define DEVICE "/dev/ISMTestDevice"
int main()
{
        int i, fd;
        char ch, wbuf[100], rbuf[100];
        fd = open(DEVICE, O_RDWR);
        if(fd < 0) {
                printf("Device file opening error.\n");
                exit(1);
        }
        printf("r = read from device\n w = write to device\n enter command:");
        scanf("%c", &ch);
        switch(ch)
        {
                case 'w':
                        printf("enter data less than 100 characters:");
                        scanf("%[^\n]", wbuf);
                        write(fd, wbuf, sizeof(wbuf));
                        break;
                case 'r':
                        read(fd, rbuf, sizeof(wbuf));
                        printf("data read from device:%s\n", rbuf);
                        break;
        }
        return 0;
}
The above program compiles without any errors. But when I execute the program with case 'w', the control is not coming to the "scanf("%[^\n]", wbuf);" statement and instead of that command prompt is appearing as like below.
output:
[root@localhost char_cdev]# ./a.out 
r = read from device
w = write to device
enter command:w
enter data less than 100 characters:[root@localhost char_cdev]#
