Thursday, February 11, 2016

Threading in C example

#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<stdlib.h>
#include<pthread.h>
pthread_t tid,tid1;
    void* myfunction(void *arg)
    {   
    int ctr=0;
    for(ctr=1;ctr<=5;ctr++)
    {
    printf("Inside First Thread ctr=%d\n",ctr);
    sleep(5);
    }
    printf("Child thread completed ");
    return NULL;
    }
        void* myfunction1(void *arg)
        {   
        int ctr=0;
        for(ctr=1;ctr<=5;ctr++)
        {
        printf("Inside Second Thread ctr=%d\n",ctr);
        sleep(10);
        }
        printf("Child thread completed");
        return NULL;
        }
    int main()
    {
    int ctr,err,err1;
    err=pthread_create(&tid,NULL,&myfunction,NULL);
    if(err)
    {
    printf("Error in creating thread:%s",strerror(err));
    return 1;
    }
    err1=pthread_create(&tid1,NULL,&myfunction1,NULL);
    if(err1)
    {
    printf("Error in creating thread:%s",strerror(err1));
    return 1;
    }
    for(ctr=0;ctr<=5;ctr++)
    {
    printf("Insidse main thread :ctr=%d\n",ctr);
    }
    printf("Main Thread completed");
    }

Threading in c programming

A thread is a single flow of control within a program.Thread is very much similar to a process.In fact thread is also called light-weight process.

pthread_create : Create a new Thread
Syntax: int pthread_create(pthread_t *thread,const pthread_attr_t *attr,void *(*start  routine) (void*),void *arg)
   
Description:
    The pthread_create() function starts a new thread in the calling process.The new thread  stars execution by invoking start routine();
    arg is passed as the sole argument of start routine().

Return Value:
    On success pthread_create() return 0,On error it returns an error.

How to run programe of Thread:
                         gcc filename.c -o f1 -lpthread (for execution of programe)
                        ./ f1                 (to run programe)
                      where f1 is executable file name

Note:    we can also run this programe as
               gcc filename.c -lpthread(for execution)
            ./a.out(to run programe)

Tuesday, February 9, 2016

Write an application to print x and y co-ordinate on 7 segment after touch....

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/input.h>

#define  NODE_EXP                          "/dev/7seg_led"  /* Device name */
#define  SEG_7_LED_ON                  1  
#define  SEG_7_LED_WRITE            2
#define  SEG_7_LED_CLEAR           3
#define  SEG_7_LED_OFF                4

int main()
{
    int fd;
    char buff[256] = "Name";
    int i,rb,m;
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */
    struct input_event ev;
    struct input_absinfo ab;   //absolute info//
    if ((fd = open("/dev/input/touchscreen0", O_RDONLY)) < 0)
    {
     printf ("Error Opening the Device\n");
     return 1;
    }
      ioctl(fd, EVIOCGNAME(sizeof(buff)), buff);
      printf("Touch Input device name: \"%s\"\n", buff);
     /* ******************Print message on 7seg starting function ************** */
    /* open as blocking mode */
    exp_dev = open(NODE_EXP, O_RDWR);     
    if (exp_dev < 0)
    {
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

   if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )     
   {
    printf("%d---> Error in switching OFF the LED \r\n",res);
    getchar();
    close(exp_dev);
    return 1;
   }
          
    /* ******************Print message on 7seg starting function ************** */ 

    for (i = 0; i < 5; i++)
    {
     rb=read(fd,&ev,sizeof(struct input_event));
     printf ("After read\n");
    if ((ev.type == 1) && (ev.code == 330))
        {
     printf ("Touch Event = %d\n",ev.code);
     }
    if ((ev.type == 3) && (ev.code == 0))
        {
     printf ("X Value  = %d\n",ev.value);
     printf ("X Value...  = %d\n",ev.value/24);
     m=ev.value/24;
     printf ("X  Value  = %x\n",m);
    if (res=ioctl(exp_dev,SEG_7_LED_WRITE, m) < 0 )
    {
     printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
     getchar();
     close(exp_dev);
     return 1;
     }
         }
    if ((ev.type == 3) && (ev.code == 1))
        {
         printf ("Y Value  = %d\n",ev.value);
        }
    if ((ev.type == 3) && (ev.code == 24))
        {
         printf ("Touch Pressure  = %d\n",ev.value);
        }
    }
    /* *******************Print message on 7seg closing function *************** */
        printf ("Press any key to exit from the program\n");
        getchar();
        if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 )
        {
         printf("%d---> Error in Clearing the LED \r\n",res);
         getchar();
         close(exp_dev);
          return 1;
          }
         if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
          {
           printf("Error in switching OFF the LED \r\n");
           getchar();
           close(exp_dev);
           return 1;
           }
              close(exp_dev);
     /* *******************Print message on 7seg closing function *************** */
    return 0;
}

Wap a programe to activate GLCD screen..

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/input.h>

int main()
  {
    int fd;
    char buff[256] = "Name";
    int i,rb;
        struct input_event ev;
        struct input_absinfo ab;   //absolute info//

     if ((fd = open("/dev/input/touchscreen0", O_RDONLY)) < 0)
     {
       printf ("Error Opening the Device\n");
       return 1;
     }
      ioctl(fd, EVIOCGNAME(sizeof(buff)), buff);
      printf("Touch Input device name: \"%s\"\n", buff);

        for (i = 0; i < 5; i++)
       {
        rb=read(fd,&ev,sizeof(struct input_event));
        printf ("After read\n");
        if ((ev.type == 1) && (ev.code == 330))
        {
         printf ("Touch Event = %d\n",ev.code);
        }

        if ((ev.type == 3) && (ev.code == 0))
        {
         printf ("X Value  = %d\n",ev.value);
        }
        if ((ev.type == 3) && (ev.code == 1))
        {
         printf ("Y Value  = %d\n",ev.value);
        }
        if ((ev.type == 3) && (ev.code == 24))
        {
         printf ("Touch Pressure  = %d\n",ev.value);
        }
    }
    return 0;
 }

Stock Market

/* This  is a program for stock market which operates following these operations:    
 1.Register company: In this case it will be register three companies and store these informations inside a file. 
2.Show Company: In this case it will show the details of those three companies which are already stored inside a file. 
Company Details:
                           1. Name of company
                           2. Location of Company
                           3.Annual Income of Company

Note: Name and location of company will be display on CLCD screen where as Annual income of company will be display on 7 Segment. 
*/


#define SIZE 3
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>

#define  NODE_EXP                         "/dev/fpga_char_lcd"   /* Device name */
#define  LCD_ON                             1 
#define  LCD_CLEAR                       2
#define  LCD_SET_HOME                3
#define  LCD_CURSOR_BLINK        4
#define  LCD_DATA_WRITE             5
#define  LCD_OFF                            6

#define  NODE_EXP1                     "/dev/7seg_led"  /* Device name */
#define  SEG_7_LED_ON                 1  
#define  SEG_7_LED_WRITE           2
#define  SEG_7_LED_CLEAR           3
#define  SEG_7_LED_OFF                4

typedef struct
{
    int turn_over;
    char name[20];
    char address[20];
    //char address[20];
} company;

int main (int argc,char *argv[])
{
    int fd= 0;
    int ctr,n;
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */
    int exp_dev1= 0; /* exp_dev1 is file descriptor */
    int ret1,res1= 0;  /* return value of system call */

    size_t sw,sp,sj,choice;
    char dummy[40];
    company comp[SIZE], *sptr;
    sptr = comp;     // Eroor may be possible at this point //
   
    //char p[]="This is my first programme of file handling in mtlc";
    while(1)
    {
    printf("Press 1 for Register new company Details:\n");
    printf("Press 2 to show company Details:\n");
    printf("Enter your choice :\n");
    scanf("%d",&choice);
    if(argc!=2)
    {
       printf("\n ERROR: Usage:: File_w <filename> \n");
       return 1;
    }
/* ******************************Open Device**************************  */
    exp_dev = open(NODE_EXP, O_RDWR);     
        if (exp_dev < 0)
    {
        fprintf(stderr, "Open error: %s\n", NODE_EXP);
        return 1;
    }
/* ****************************Open Device**************************  */
     exp_dev1 = open(NODE_EXP1, O_RDWR);     
        if (exp_dev1 < 0){
    fprintf(stderr, "Open error: %s\n", NODE_EXP1); // may be fault //
    return 1;
        }

    /* open as blocking mode */
    switch(choice)
    {
   
/* ****************Application : Register Company **********************   */
    case 1:
    fd = open(argv[1], O_WRONLY | O_CREAT);
    if (fd < 0){
    printf("error opening");
    return 1;
    }
    printf("File is ready to open");
    for(ctr=0; ctr<SIZE; ctr++)
    {
        printf("Welcome !Register your company details:\n ");
        printf("Enter name of company :\n");
        scanf("%s",&comp[ctr].name);
        printf("Enter Address Details of company :\n");
        scanf("%s",&comp[ctr].address);
        printf("Annual turn_over of company :\n");
        scanf("%x",&comp[ctr].turn_over);
    }
    sw=write(fd,sptr,sizeof(comp)*3);
    if(sw<=0)
    {
        printf("\n Zero bytes has been written ....");
        return 1;
    }
   
    printf("file name is :%s\n",argv[1]);
    printf("Registration has been completed \n thank u!\n Have a nice day\n");
    /*for(ctr=0; ctr<SIZE; ctr++)
    {
       
        printf("Registration has been completed \n thank u!\n Have a nice day\n");
    }*/
    getchar();
        close(fd);
    break;
/* ****************Application : Register Company **********************   */

/* ******************Application : Read Company Detail********************  */   
    case 2:
       if (res=ioctl(exp_dev,LCD_ON, NULL) < 0 )      /* Ioctl */
        {
         printf("%d---> Error in switching OFF the LCD \r\n",res);
         getchar();
         close(exp_dev);
         return 1;
         }
        printf("\n LCD_ON: Hit A Key To Continue...");
        getchar();
        if (res=ioctl(exp_dev,LCD_CLEAR, NULL) < 0 )
        {
         printf("%d---> Error in Clearing the LCD \r\n",res);
         getchar();
         close(exp_dev);
         return 1;
        }
       if (res=ioctl(exp_dev,LCD_SET_HOME, NULL) < 0 )
       {
        printf("Error in Set home the LCD \r\n");
        getchar();
        close(exp_dev);
        return 1;
        }
       if (ioctl(exp_dev,LCD_CURSOR_BLINK , NULL) < 0 )
       {
        printf("Error inCursor blink in LCD \r\n");
        getchar();
        close(exp_dev);
        return 1;
        }

    /* Open file for read purpose */
/* ****************************Function for 7 Segment ********************** */
       if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )      /* Ioctl */
       {
        printf("%d---> Error in switching OFF the LED \r\n",res);
        getchar();
        close(exp_dev);
        return 1;
        }

/* ****************************Function for 7 Segment ********************** */
    fd = open(argv[1], O_RDONLY);
    if (fd < 0)
    {
     printf("error opening");
     return 1;
     }
         printf("File is ready to open");
         sw = read(fd,sptr,sizeof(comp)*3);
    if(sw<=0)
    {
     printf("\n Zero bytes has been written ....");
     return 1;
     }
    printf("file name is :%s\n",argv[1]);
    for(ctr=0; ctr<SIZE; ctr++)
    {
     printf("\n SPTR = %u \n", sptr);
     sptr++;
    }
    sptr=comp;
    for(ctr=0; ctr<SIZE; ctr++)
    {
     strcpy(dummy, sptr->name);
     strcat(dummy, ", ");
     strcat(dummy, sptr->address);
     printf("\n SPTR = %u, Dummy = %s \n", sptr, dummy);
     printf("\n%d.: Details: Name: %s,\tAddress: %s,\tTurn Over: %d, %x", ctr+1,    sptr->name, sptr->address, sptr->turn_over, sptr->turn_over);
    if (ioctl(exp_dev,LCD_DATA_WRITE, dummy) < 0 )
    {
     printf("Error in switching OFF the LCD \r\n");
     getchar();
     close(exp_dev);
     return 1;
     }
    if (res1=ioctl(exp_dev1,SEG_7_LED_WRITE,sptr->turn_over) < 0 )
    {
     printf("%d---> Error in writing to the 7-Seg LED \r\n",res1);
     getchar();
     close(exp_dev1);
     return 1;
     }
     printf("\n Hit A Key for next record...");
     getchar();
     if(ctr<2)
     {
      sptr++;
      }
  }
   getchar();
  if (ioctl(exp_dev,LCD_OFF, NULL) < 0 )
  {
   printf("Error in switching OFF the LCD \r\n");
   getchar();
   close(exp_dev);
   return 1;
   }
  if (res1=ioctl(exp_dev1,SEG_7_LED_CLEAR, NULL) < 0 )
  {
   printf("%d---> Error in Clearing the LED \r\n",res);
   getchar();
   close(exp_dev1);
   return 1;
   }
  if (ioctl(exp_dev1,SEG_7_LED_OFF, NULL) < 0 )
  {
   printf("Error in switching OFF the LED \r\n");
   getchar();
   close(exp_dev1);
   return 1;
   }
       close(exp_dev1);
       close(exp_dev);
       printf("\n Hit A Key To Stop...");
       getchar();
       close(fd);
   break;
default :
    printf("! sorry invalid request ..");
    break;
    printf("Press 1 for continue and press 0 for exit :...");
    scanf("%d",&n);
    if(n==0)
    {
    exit(0);
    }
}
}
    return 0;
}

Monday, February 8, 2016

Wap a menu driven programe to store some information inside a file and read information from file and print it on LCD screen.

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

#define  NODE_EXP                      "/dev/fpga_char_lcd"   /* Device name */
#define  LCD_ON                          1 
#define  LCD_CLEAR                    2
#define  LCD_SET_HOME            3
#define  LCD_CURSOR_BLINK    4
#define  LCD_DATA_WRITE         5
#define  LCD_OFF                        6

/* Application : To test the functionaity of file handling */


int main (int argc,char *argv[])
{
 int fd= 0;
 size_t sw,sk,choice;
 int exp_dev= 0; /* exp_dev is file descriptor */
 int ret,res= 0;  /* return value of system call */
char p[]="This is my first programme of file handling in mtlc for read and           write";
char bufr[200];
printf("*************************************************\n");
printf("press 1 for write information inside file\n");
printf("press 2 for read information from file\n");
printf("Enter your choice :");
scanf("%d",&choice);
if(argc!=2)
    {
       printf("\n ERROR: Usage:: File_w <filename> \n");
       return 1;
    }
    switch(choice)
    {
    // ******************* Write message from a file ***********************//
    case 1:
    /* open as blocking mode */
    fd = open(argv[1], O_WRONLY | O_CREAT);
    if (fd < 0){
    printf("error opening");
    return 1;
       }
    printf("File is ready to open");
    sw = write(fd,p,sizeof(p));
    if(sw<=0)
    {
        printf("\n Zero bytes has been written ....");
        return 1;
    }
    printf("file name is %s with text is %s with size %d\n",argv[1],p,sw);
    getchar();
        close(fd);
   
  // ******************* Write message from a file ***********************//
     // ******************* Read message from a file ***********************//
    case 2:
    fd = open(argv[1], O_RDONLY);
    if (fd < 0){
    printf("error opening");
    return 1;
        }
    printf("File is ready to open");
    //sk = read(fd,bufr,sizeof(bufr));
    sk = read(fd,bufr,100);
    if(sk<=0)
    {
        printf("\n Zero bytes has been written ....");
        return 1;
    }
   
    //printf("file name is %s with text is %s with size %d",sw);
    printf("\n file name is %s with text is %s with size %d\n",argv[1],bufr,sk);
    sk = write(1,bufr,20);
    getchar();
       close(fd);
   // ******************* Read message from a file ***********************//

   // ***************** Read message on LCD screen*********************//
    exp_dev = open(NODE_EXP, O_RDWR);     
     if (exp_dev < 0){
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

                if (res=ioctl(exp_dev,LCD_ON, NULL) < 0 )      /* Ioctl */
                {
                 printf("%d---> Error in switching OFF the LCD \r\n",res);
                 getchar();
                 close(exp_dev);
                 return 1;
                }
        printf("\n LCD_ON: Hit A Key To Continue...");
        getchar();
            if (res=ioctl(exp_dev,LCD_CLEAR, NULL) < 0 )
            {
            printf("%d---> Error in Clearing the LCD \r\n",res);
            getchar();
            close(exp_dev);
            return 1;
           }
            if (res=ioctl(exp_dev,LCD_SET_HOME, NULL) < 0 )
            {
            printf("Error in Set home the LCD \r\n");
            getchar();
            close(exp_dev);
            return 1;
            }
            if (ioctl(exp_dev,LCD_CURSOR_BLINK , NULL) < 0 )
            {
             printf("Error inCursor blink in LCD \r\n");
             getchar();
             close(exp_dev);
             return 1;
             }
        if (ioctl(exp_dev,LCD_DATA_WRITE,p) < 0 )
         {
          printf("Error in switching OFF the LCD \r\n");
          getchar();
           close(exp_dev);
           return 1;
           }
        printf("\n Hit A Key To Continue...");
        getchar();
        if (ioctl(exp_dev,LCD_OFF, NULL) < 0 )
        {
         printf("Error in switching OFF the LCD \r\n");
         getchar();
         close(exp_dev);
         return 1;
         }

      close(exp_dev);
      printf("\n Hit A Key To Stop...");
      getchar();
      break;
    // ********************* Read message on LCD screen*********************//
  
    default:
    printf("Sorry! invalid request \n");
    getchar();
       close(fd);
    break;

    }

    return 0;
}

Wap a program to print name of user taken from user .

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#define  NODE_EXP                           "/dev/fpga_char_lcd"

#define  LCD_ON                                1   /* Device name */
#define  LCD_CLEAR                          2
#define  LCD_SET_HOME                   3
#define  LCD_CURSOR_BLINK           4
#define  LCD_DATA_WRITE                5
#define  LCD_OFF                                6


/* Application : To test the functionaity of LCD Driver */

int main ()
  {
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */
    char name[10];
    exp_dev = open(NODE_EXP, O_RDWR);     
    if (exp_dev < 0)
   {
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

                if (res=ioctl(exp_dev,LCD_ON, NULL) < 0 )      /* Ioctl */
                {
                    printf("%d---> Error in switching OFF the LCD \r\n",res);
                    getchar();
                    close(exp_dev);
                    return 1;
                }
               if (res=ioctl(exp_dev,LCD_CLEAR, NULL) < 0 )
               {
                  printf("%d---> Error in Clearing the LCD \r\n",res);
                  getchar();
                  close(exp_dev);
                  return 1;
             }
            if (res=ioctl(exp_dev,LCD_SET_HOME, NULL) < 0 )
            {
             printf("Error in Set home the LCD \r\n");
             getchar();
             close(exp_dev);
             return 1;
            }
            if (ioctl(exp_dev,LCD_CURSOR_BLINK , NULL) < 0 )
            {
             printf("Error inCursor blink in LCD \r\n");
             getchar();
             close(exp_dev);
              return 1;
             }
    /* *******************INPUT TAKEN FROM USER ****************** */
                       printf("Enter your name :");
                       scanf("%s",&name);
  /* *******************INPUT TAKEN FROM USER ****************** */
        if (ioctl(exp_dev,LCD_DATA_WRITE, name) < 0 )
       {
        printf("Error in switching OFF the LCD \r\n");
        getchar();
        close(exp_dev);
         return 1;
         }
        if (ioctl(exp_dev,LCD_OFF, NULL) < 0 )
        {
         printf("Error in switching OFF the LCD \r\n");
         getchar();
         close(exp_dev);
         return 1;
         }

    close(exp_dev);
    printf("\n Hit A Key To Stop...");
    getchar();

    exit(1);
}

Wap a Programe to print some numbers or message on LCD screen.

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define  NODE_EXP                           "/dev/7seg_led"
#define  LCD_ON                                1   /* Device name */
#define  LCD_CLEAR                         2
#define  LCD_SET_HOME                 3
#define  LCD_CURSOR_BLINK         4
#define  LCD_DATA_WRITE              5
#define  LCD_OFF                             6

/* Application : To test the functionaity of LCD Driver */

int main ()
 {
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */

    /* open as blocking mode */
    exp_dev = open(NODE_EXP, O_RDWR);     
    if (exp_dev < 0){
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

         if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )   
              {
                    printf("%d---> Error in switching OFF the LED \r\n",res);
                    getchar();
                    close(exp_dev);
                    return 1;
                }
           if (res=ioctl(exp_dev,SEG_7_LED_WRITE, 0x1234) < 0 )
         {
            printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
            getchar();
            close(exp_dev);
            return 1;
         }
          printf ("Press any key to exit from the program\n");
          getchar();
          if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 )
         {
            printf("%d---> Error in Clearing the LED \r\n",res);
            getchar();
            close(exp_dev);
             return 1;
            }
           if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
          {
            printf("Error in switching OFF the LED \r\n");
            getchar();
            close(exp_dev);
            return 1;
             }
          close(exp_dev);
         exit(1);
  }

Thursday, February 4, 2016

Introduction


Our Team


Write a programe to print 1234 on 7 segment ...

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define  NODE_EXP                  "/dev/7seg_led"

#define  SEG_7_LED_ON                 1   /* Device name */
#define  SEG_7_LED_WRITE           2
#define  SEG_7_LED_CLEAR           3
#define  SEG_7_LED_OFF               4


/* Application : To test the functionaity of LCD Driver */

int main ()
{
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */

    /* open as blocking mode */
    exp_dev = open(NODE_EXP, O_RDWR);     
    if (exp_dev < 0){
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

                if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )      /* Ioctl */
        {
                    printf("%d---> Error in switching OFF the LED \r\n",res);
            getchar();
                    close(exp_dev);
                    return 1;
                }
           if (res=ioctl(exp_dev,SEG_7_LED_WRITE, 0x1234) < 0 ){
            printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
            getchar();
            close(exp_dev);
            return 1;
        }
        printf ("Press any key to exit from the program\n");
        getchar();
                if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 ){
                    printf("%d---> Error in Clearing the LED \r\n",res);
            getchar();
                    close(exp_dev);
                    return 1;
                }
                if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 ){
                    printf("Error in switching OFF the LED \r\n");
            getchar();
                    close(exp_dev);
                    return 1;
                }

    close(exp_dev);
    exit(1);
}

Write a programe to print some number on 7 segment taken from user.

#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define  NODE_EXP                         "/dev/7seg_led"

#define  SEG_7_LED_ON                 1   /* Device name */
#define  SEG_7_LED_WRITE           2
#define  SEG_7_LED_CLEAR           3
#define  SEG_7_LED_OFF                4


/* Application : To test the functionaity of LCD Driver */

int main ()
{
    int exp_dev= 0; /* exp_dev is file descriptor */
    int ret,res= 0;  /* return value of system call */
    int num;  /*  input value */
    /* open as blocking mode */
    exp_dev = open(NODE_EXP, O_RDWR);     
    if (exp_dev < 0){
    fprintf(stderr, "Open error: %s\n", NODE_EXP);
    return 1;
    }

                if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )      /* Ioctl */
        {
                    printf("%d---> Error in switching OFF the LED \r\n",res);
                    close(exp_dev);
                    return 1;
                }
/* *********************INPUT TAKEN FROM USER*********************** */
        printf("Enter input from user ");
                scanf("%d",&num);
/* *********************INPUT TAKEN FROM USER*********************** */
           if (res=ioctl(exp_dev,SEG_7_LED_WRITE, num) < 0 )
         {
            printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
            close(exp_dev);
            return 1;
          }
        printf ("Press any key to exit from the program\n");
        getchar();
                if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 )
               {
                    printf("%d---> Error in Clearing the LED \r\n",res);
                    close(exp_dev);
                    return 1;
                }
                if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
             {
                    printf("Error in switching OFF the LED \r\n");
                    close(exp_dev);
                    return 1;
                }

    close(exp_dev);
    exit(1);
}