Thread: parameters in main()

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    6

    Unhappy parameters in main()

    what does the parameters mean in the main() function, and how to use this kind of command parameters?
    Code:
    int main(int argc, char * argv[])
    {
      
       char message[20];
    
       if(argc<2)
       {
    	   printf("Fetal error: Too few arguments!\n");
    	   exit(0);
       }
       while(fgets(message, 20, stdin) != NULL)
       {
          if( strncmp(message, "TERMINATE", 9) == 0)
          {
                fprintf(stderr, "Node %s forwarding on : %s\n", argv[1], message);
    	    fprintf(stderr, "Node %s terminating\n", argv[1]);
                fprintf(stdout, "%s", message);
    	    exit(1);
          }
          sleep(1);
          if(*message == *argv[1])
          {
             fprintf(stderr,"Node %s is keeping : %s\n", argv[1], message);
             fprintf(stderr,"That's for me!\n");
          }
          else 
          {
            
                fprintf(stderr,"Node %s forwarding on : %s\n", argv[1], message);
    	    fprintf(stdout, "%s", message);
                fprintf(stderr,":\n");
             
          }
          
       }
       return 0;
    }

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    this is a good ref:

    http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

    look at functions/program startup.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 10-15-2008, 03:38 AM
  2. memory leaks
    By TehOne in forum C Programming
    Replies: 4
    Last Post: 10-10-2008, 09:33 PM
  3. Replies: 6
    Last Post: 09-23-2008, 07:27 PM
  4. Main Declaration error
    By starkhorn in forum C++ Programming
    Replies: 11
    Last Post: 06-22-2005, 09:04 AM
  5. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM