Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

compiler warning!

Posted on 2003-03-05
5
Medium Priority
?
269 Views
Last Modified: 2010-04-15
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","nov","dec"};
  char *days[] = {"sun","mon","tues","wed","thurs","fri","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;
}
0
Comment
Question by:kavvang
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Exceter
ID: 8074127
Could you post the complete source file?
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8074152

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
0
 

Author Comment

by:kavvang
ID: 8075199
so, what is the option or how do i fix this problem. sorry, i can't post the complete source file.
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 200 total points
ID: 8075682

You have to decide if the program really should be in an infinite loop.

If so, just remove the "return 0;".

If not, you need to modify the "while (1)" loop.  You can either loop on a condition or insert a conditional break.

If you want to loop on a condition, replace:

while (1)

with:

while (ReasonForLooping)

Or in the loop enter the statement:

if (!ReasonForLooping)
  break;


Of course, "ReasonForLooping" is your condition, not a literal.


Good Luck,
Kdo

0
 

Author Comment

by:kavvang
ID: 8075914
Kdo, thank you... I am glad you helped
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question