Results 1 to 4 of 4

Thread: How to return an array from function

  1. #1
    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?

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    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; 
      )

  3. #3
    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.

  4. #4
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,567,609.91515 seconds with 17 queries