Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-10-2009
Member
 
Join Date: Apr 2009
Posts: 29
How to return an array from function

Can any one tell me how to make a function that returns an array of characters in C? A simple question that I can not solve. Do I need to declare pointer to return another array?
Reply With Quote
  #2  
Old 02-10-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to return an array from function

Code:
# include <stdio.h> 
  # include <stdlib.h> 

 void function (int *) 
  ( 
       int a = array [0]; 

       tab [0] = array [1]; 
       tab [1] = a; 
  ) 

  int main (void) 
  ( 
       int * a = array (5 * sizeof (* tab)); 
       if (tab! = NULL) 
       ( 
            tab [0] = 0; 
            tab [1] = 1; 

            function (tab); 

            printf ( "% d% d \ n", tab [0], tab [1]); 
       ) 

             return 0; 
  )
Reply With Quote
  #3  
Old 02-10-2009
Member
 
Join Date: Jan 2009
Posts: 199
Re: How to return an array from function

To make a function that returns an array of characters you are not required to use the IsArray function to ensure that the procedure indeed returned an array. You have to use dynamic allocation. If a procedure returns a value of type Variant, you might want to check its contents before performing array operations.
Reply With Quote
  #4  
Old 02-10-2009
Member
 
Join Date: Dec 2008
Posts: 177
Re: How to return an array from function

Code:
char * string (char * ch) 
   ( 
      return ch; 
   ) 
  / * main * / 
  printf (string ( "hello!"));
The function returns the string that it send as a parameter.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to return an array from function"
Thread Thread Starter Forum Replies Last Post
SSH return function Elizabeth Allen Networking & Security 5 22-04-2010 02:38 PM
Is it possible for a function to return two values? hounds Software Development 5 13-03-2010 07:51 PM
How can I return different class in one function? Madaleno Software Development 4 10-02-2010 09:45 PM
How to return a dynamically allocated char array? Chrisch Software Development 3 09-10-2009 01:47 PM
Return a strongly typed array from the ToArray method Eleazar Software Development 2 06-05-2009 01:32 PM


All times are GMT +5.5. The time now is 12:15 AM.