title: C #define string, Servname not supported for ai_socktype
body: <p>I am trying to write socket program in C. My entire code works fine when I do</p>
  
  <pre><code>#define PORT "3333"
  </code></pre>
  
  <p>but not </p>
  
  <pre><code>#define PORT getParameter("setting.ini","PORT")
  </code></pre>
  
  <p>Basically, the getParameter just opens the setting.ini file and read through, look for the variable and its value then return it. The only reason I am doing this is because I don't want the port number to be hardcoded in my code. I got:</p>
  
  <blockquote>
    <p>"Servname not supported for ai_socktype" </p>
  </blockquote>
  
  <p>I have no clue what causes this error. 
  Any ideas? </p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  char *substring(char* str, int start, int length) {
      char *newString = (char *)malloc(length * sizeof(char)+1);
      int i, x = 0;
      int end=start+length-1;
      for(i = start ; i &lt;= end; i++)
          newString[x++] = str[i];
      newString[x] = '\0';
      return newString;
  }
  
  char *getParameter(char *fName, char *pName)
  {
     FILE *fr;
     char line[80];
     int i;
  
     fr = fopen (fName, "r");  /* open the file for reading */
  
     while(fgets(line, 80, fr) != NULL)
     {
     i = strcspn (line,"=");
     if(strcmp(pName,substring(line,0,i))==0){
              char *value = substring(line,i+1,strlen(line)-i);
              fclose(fr);
              return value;
          }
     }
     fclose(fr);
  }
  
  int main(void){
      char *PORT = getParameter("setting.ini","PORT");
      const int BACKLOG = atoi(getParameter("setting.ini","BACKLOG"));
      printf("%s\n",PORT);
      printf("%d\n",BACKLOG);
      return 0;
  }
  </code></pre>