How to write a C Program to Alarm Check in C programming Language ?
- /*Alarm check */
- #include <sys/types.h>
- #include <sys/ioctl.h>
- #include <fcntl.h>
- #include <errno.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <signal.h>
- #include <time.h>
- /* Main program. */
- int main(int argc, char **argv)
- {
- int fd;
- FILE *log;
- /* These TIOCM_* parameters are defined in <linux/termios.h>, which */
- /* is indirectly included here. */
- int set_bits;
- int flags;
- int sleep_time;
- int pc;
- time_t now;
- char strtime[30];
- if (argc != 2) {
- printf("Usage: relays <device> \n");
- exit(1);
- }
- /* Open monitor device. */
- if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
- fprintf(stderr, "port: %s: %s\n", argv[1], sys_errlist[errno]);
- exit(1);}
- /* Get the bits to set from the command line. */
- sscanf(argv[2], "%x", &set_bits);
- sscanf(argv[3], "%d", &sleep_time);
- /* Set the command line specified bits (& only the command line */
- /* specified bits). */
- ioctl(fd, TIOCMSET, &set_bits);
- sleep(1);
- ioctl(fd, TIOCMGET, &flags);
- time(&now);
- printf("%d\t",now);
- printf("%x\t", flags);
- if (flags & 0x100) { printf ("on\t"); } else { printf ("off\t"); }
- if (flags & 0x80) { printf ("on\t"); } else { printf ("off\t"); }
- if (flags & 0x40) { printf ("on\t"); } else { printf ("off\t"); }
- if (flags & 0x20) { printf ("on\t"); } else { printf ("off\t"); }
- printf("%s",ctime(&now));
- close(fd);
- }
Learn More :
Alarm
Clock
Check
- CHECKING LEAP YEAR USING C PROGRAM.
- Check given number is prime number or not using c program.
- Write a c program to check given string is palindrome number or not.
- C program to Check While packet(s) hasn't been acked
- C Program to Check Prime Use Loop And Recursive
- Given a numerical value, check if at least one of the elements of the vector is equal to the numerical value if so, say where in the negative case, say that there is no.
- C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not
- C Program To Check The Given Value Is Vowel
- C Function to Check Vowel
- C Program To Check Leap Year
- C Program To Check If It Is A Palindrome Numbers Or Not
- C Program to Check if a number is in an array[1000]
- Armstrong Number Checker in C
- C Program to Check Given String is Palindrome or Not
- C Program to Check Whether Number Is Perfect Or Not
- C Program To Read A Parenthesised Infix Expression From The User And Check Whether It Is Well Parenthesised Or Not
- Input a Number and Check if it's Palindrome or not C Program
- Input Number and Check if it's Armstrong C Program
- Input Number and Check if it's Even or Odd C Program