title: For loop not being executed C
body: <p>I am trying to scan any ports that are open and saving those which are in text file. The program displays the first loop ( checking whether or not the arguments are correct) but for some reason skips the entire for loop. I am a newbie in c so any help is much appreciated</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define HTTP_PORT 80
  
  int main(int argc, char ** argv)
  {
      int sockfd=0;
      int min = atoi(argv[1]);
      int max = atoi(argv[2]);
      struct sockaddr_in serv_addr;
      struct hostent *url;
  
      for(int i = 0; i &lt; argc; i++)
      {
          printf("%d, is %s\n",i,argv[i]);
      }
  
      sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      if (sockfd &lt; 0) {
          fprintf(stderr, "ERROR: Failed to open socket\n");
          return 1;
      }
  
      url = gethostbyname(argv[3]); /* does not support IP6 */
      if (url == NULL) {
          fprintf(stderr, "ERROR: Host not found\n");
          return 2;
      }
  
      printf("Scanning ports %d - %d\n",  min, max);
  
      FILE * file = fopen("/home/llp2/Desktop/Assignment/ports.txt", "w");//open log file
  
      for (unsigned short port = min; port &lt; max; port++)//loop through and scan all ports
      {
              memset(&amp;serv_addr, 0, sizeof(serv_addr));
              serv_addr.sin_family = AF_INET;
              memcpy(&amp;serv_addr.sin_addr, url-&gt;h_addr, url-&gt;h_length);
              serv_addr.sin_port = htons(HTTP_PORT);
  
          /* Connect to the server */
          if (connect(sockfd, (struct sockaddr*) &amp;serv_addr, sizeof(serv_addr)) &gt; 0) 
          {   
                  //if the port is open get information about that port and print it to the log file
                  char host[128];
                  char service[128];
                  getnameinfo((struct sockaddr*)&amp;serv_addr, sizeof serv_addr, host, (sizeof host), service, sizeof service, 0);
                  printf("Port : %d, Service : %s, Open\n", port, service);
                  fprintf(file, "Port : %d, Service : %s, Open\n", port, service);
          }
  
          close(sockfd);
      }
  
          fclose(file);//Close the file
  
      return 0;
  }
  </code></pre>