this is the same code as i was able to recover from formatting:
#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <time.h>
#define COPYMODE 0644
int main (int argc, char * argv []) {int i, nRead, fd; int source; int STATE_OK = 0; int STATE_WARNING = 1; int STATE_CRITICAL = 2; int STATE_UNKNOWN = 3; int system_paused = 0;
char buf [5]; int testnumber;
if ((fd = open (argv [1], O_RDONLY)) == -1) {printf ("failed open:% s", argv [1]); return STATE_UNKNOWN; } else {nRead = read (fd, buf, 5); } close (source);
if (buf [4] == 'P') {printf ("Software Paused"); return STATE_WARNING; } else {return STATE_OK; } time_t ltime; / * calendar time / struct tm Tm; ltime = time (NULL); / get current cal time * / Tm = localtime (& ltime);
int test; test = Tm-> tm_hour + Tm-> tm_min; printf ("% d", test); printf ("% d", strtoi (buf)); }
this is the version that does what you specified:
#include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <time.h>
#define COPYMODE 0644
int main (int argc, char * argv []) {int i, nRead, fd; int source; int STATE_OK = 0; int STATE_WARNING = 1; int STATE_CRITICAL = 2; int STATE_UNKNOWN = 3; int system_paused = 0;
char buf [5]; int testnumber;
if ((fd = open (argv [1], O_RDONLY)) == -1) {printf ("failed open:% s", argv [1]); return STATE_UNKNOWN; } else {nRead = read (fd, buf, 5); } close (source);
if (buf [4] == 'P') {printf ("Software Paused"); return STATE_WARNING; } / * else {return STATE_OK; buf [4] = 0; } * / time_t ltime; / * calendar time * / struct tm * Tm; ltime = time (NULL); / * get current cal time * / Tm = localtime (& ltime);
int test; test = Tm-> tm_hour + Tm-> tm_min; printf ("% d \ n", test); printf ("% d \ n", atoi (buf)); }
The biggest problem with your code is the if statement with return values ββin each branch, ensuring that nothing is executed after the if statement is executed.