title: how to pass an integer to a function and return a string
body: <p>I am trying to write a function (and failing badly!!) that passes an int as a parameter and returns a string which is generated from a mysql query - see below code:</p>
  
  <p>I would like after I have have that working like to be able to pass a number of parameters (1 int and 2 chars) and have returned 3 strings, I guess those will require a struct and pointers but i'll start with the simple stuff.. crawl first..run later :)</p>
  
  <p>Here is the code I have written I have removed the function but it's failing on compile at the line</p>
  
  <pre><code>retString =  strFunction(Value); 
  </code></pre>
  
  <p>with the error:</p>
  
  <pre><code>warning: assignment makes pointer from integer without a cast [enabled by default]
  </code></pre>
  
  <p>I can post the full code if required..</p>
  
  <p>Many Thanks in advance.</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  
  char *retString;
  retString =  strFunction(Value);
  printf("The Return string is:  %s", retString);
  Exit (0);
  
  }
  
  
  char *strFunction(int Value)
  {
  
  perform code here using value;
  Return retString;
  
  }
  </code></pre>
  
  <p>Okay here's the full code.. messy I know... embarrassment got the better of me posting originally.. </p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  int Exhibit = 1;
  char *rtn_Exhibition;
  rtn_Exhibition =  rtn_ex(Exhibit);
  printf("The Exhibition is set to:  %s", rtn_Exhibition);
  }
  
  
  char *rtn_ex(int Exhibit)
  {
  static char selectEx[2];
  unsigned int i;
  char selectEx_rtn[20];
  memset(selectEx, 0, sizeof(selectEx));
  sprintf(selectEx, "SELECT exhibition_description FROM exhibitions WHERE exhibition_id='%d'",Exhibit);
  printf("\nThe SELECT statement you have built is: %s\n", selectEx );
  connectDB();
  if (mysql_query (conn, selectEx) != 0)
      {
          print_error (conn, "mysql_query() failed");
      }
  else
      {
      res_set = mysql_store_result (conn); /* generate result set */
      // printf("The value of  the result set is: %d\n", res_set);    
      if (res_set == NULL)
          { 
              print_error(conn, "mysql_store_result() failed");
          }
      else
          {
          //process_result_set(conn, res_set);
          MYSQL_ROW row;
          while ((row = mysql_fetch_row (res_set)) != NULL)
          {
              for (i = 0; i &lt; mysql_num_fields (res_set); i++)
              {
                  sprintf(selectEx_rtn, "The exhibition name is: %s",   (row[i]));
              }
  
          }
      }
      mysql_free_result(res_set);
  }
  disconnectDB();
  return selectEx_rtn;
  }
  </code></pre>
  
  <p>Hi T Thanks for your response, in answer to your comments:</p>
  
  <p>1) That's correct, I didn't spot that. Yes there are 70 characters for the SELECT statement + the int that goes in the single quotes which will be a 1-9 number. I have adjusted the array as now 80 characters </p>
  
  <p>2) The MYSQL_RES pointer is set earlier in the program: </p>
  
  <p>MYSQL_RES *res_set; </p>
  
  <p>3) I adjusted this to 30 characters but I get an error stating that selectEX_rtn warning: function returns address of local variable. I changed selectEx_rtn to a pointer and the function works but dies straight afterwards with a segmentation fault</p>