This is completely confusing me. I have a call to a function:
Code:
case '5': if ((findfree((int)&roomnum)) < 0)
printf("No available rooms\n");
else
printf("%d is available\n", roomnum);
break;
and it leaves roomnum with a 10 digit number (when to me) the definition of the function looks like it should give the varaiable roomnum either 1-10 or return -1..
Code:
#include "hotel.h"
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
int fd;
char buf[NLINES];
int
findfree(int room)
{
ssize_t nread;
int i, j;
_Bool vacant;
if (lseek(fd, (off_t)0, SEEK_SET) < 0)
perror("problem with lseek in findfree: line 23");
for (i = 1; i <= MAXROOMS; ++i) {
if ( (nread = read(fd, buf, sizeof(buf))) < 0)
perror("problem with read in findfree function: line 21"), exit(-1);
vacant = true;
for (j = 0; j < nread; ++j) {
if (isalpha(buf[j])) {
vacant = false;
break;
}
}
if (vacant == true) {
room = i;
printf("***%d\n\n", room);
return 1;
}
}
return -1;
}
Anyone see what's wrong with this?