kavvang
asked on
compiler warning!
when i compile my program, it gives me the following warning:
"fileinfod.c", line 83: warning: statement not reached
would you please give me a suguestion how to fix this warning. Thank you and here is my program:
int main()
{
int fd, userfd;
FILE *fp;
FILE *userfp;
struct stat buffer;
time_t rawtime;
struct tm * ptm;
char input[255];
int flag;
char *months[] = {"jan","feb","mar","apr"," may","june ","july"," aug","sep" ,"oct","no v","dec"};
char *days[] = {"sun","mon","tues","wed", "thurs","f ri","sat"} ;
fp = fopen("COMM_FILE", "w+"); /* open COMM_FILE in read.write mode */
fd = fileno(fp); /* create file descriptor from file pointer */
while(1)
{
sleep(5);
rewind( fp ); /* rewind shared COMM_FILE */
lockf( fd, F_LOCK, 0 ); /* lock shared COMM_FILE */
flag = getc(fp); /* get 1st char from COMM_FILE */
if ( flag == 48) /* if char is 0 (ie meant for server */
{
printf("Server processing\n");
fscanf( fp, "%s", input); /* read data from COMM_FILE to input */
lockf( fd, F_ULOCK, 0 ); /* unlock COMM_FILE */
if ( (userfp = fopen(input, "r")) && (fstat( fileno(userfp), &buffer)) >= 0)
{
rawtime = buffer.st_atime; /* access file info filename */
ptm = localtime ( &rawtime );
rewind(fp); /* lock COMM_FILE */
lockf( fd, F_LOCK, 0);
/* write access time info back to COMM_FILE with "1" added to beginning for identifier for client */
fprintf(fp,"1%s last accessed %s %s %02d %2d:%02d:%02d %2d\n",input,
*(days+ptm->tm_wday),
*(months+ptm->tm_mon),
ptm->tm_mday,ptm->tm_hour, ptm->tm_min,
ptm->tm_sec, ptm->tm_year+1900);
lockf( fd, F_ULOCK, 0); /* unlock COMM_FILE */
}
else /* unable to open user input from client */
{
rewind(fp); /* rewind and lock COMM_FILE */
lockf( fd, F_LOCK, 0);
fprintf(fp, "1%s filename not found", input); /* write response back to COMM_FILE targeted to client */
lockf( fd, F_ULOCK, 0);
}
}
else /* COMM_FILE contenets not intended for server */
{
lockf( fd, F_ULOCK, 0 );
}
}
return 0;
}
"fileinfod.c", line 83: warning: statement not reached
would you please give me a suguestion how to fix this warning. Thank you and here is my program:
int main()
{
int fd, userfd;
FILE *fp;
FILE *userfp;
struct stat buffer;
time_t rawtime;
struct tm * ptm;
char input[255];
int flag;
char *months[] = {"jan","feb","mar","apr","
char *days[] = {"sun","mon","tues","wed",
fp = fopen("COMM_FILE", "w+"); /* open COMM_FILE in read.write mode */
fd = fileno(fp); /* create file descriptor from file pointer */
while(1)
{
sleep(5);
rewind( fp ); /* rewind shared COMM_FILE */
lockf( fd, F_LOCK, 0 ); /* lock shared COMM_FILE */
flag = getc(fp); /* get 1st char from COMM_FILE */
if ( flag == 48) /* if char is 0 (ie meant for server */
{
printf("Server processing\n");
fscanf( fp, "%s", input); /* read data from COMM_FILE to input */
lockf( fd, F_ULOCK, 0 ); /* unlock COMM_FILE */
if ( (userfp = fopen(input, "r")) && (fstat( fileno(userfp), &buffer)) >= 0)
{
rawtime = buffer.st_atime; /* access file info filename */
ptm = localtime ( &rawtime );
rewind(fp); /* lock COMM_FILE */
lockf( fd, F_LOCK, 0);
/* write access time info back to COMM_FILE with "1" added to beginning for identifier for client */
fprintf(fp,"1%s last accessed %s %s %02d %2d:%02d:%02d %2d\n",input,
*(days+ptm->tm_wday),
*(months+ptm->tm_mon),
ptm->tm_mday,ptm->tm_hour,
ptm->tm_sec, ptm->tm_year+1900);
lockf( fd, F_ULOCK, 0); /* unlock COMM_FILE */
}
else /* unable to open user input from client */
{
rewind(fp); /* rewind and lock COMM_FILE */
lockf( fd, F_LOCK, 0);
fprintf(fp, "1%s filename not found", input); /* write response back to COMM_FILE targeted to client */
lockf( fd, F_ULOCK, 0);
}
}
else /* COMM_FILE contenets not intended for server */
{
lockf( fd, F_ULOCK, 0 );
}
}
return 0;
}
Could you post the complete source file?
Most of your program is contained within a while(1) loop that has no exit. (There is no "break" within the statement and of course, the while(1) will loop forever unless a break or return occurs).
The "return 0;" is after your while loop. The compiler is telling you that this code cannot be reached because the while loop never exits.
Kdo
ASKER
so, what is the option or how do i fix this problem. sorry, i can't post the complete source file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kdo, thank you... I am glad you helped