Go Back   The UNIX and Linux Forums > Top Forums > Programming
.
google site



Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-19-2007
Registered User
 

Join Date: Nov 2007
Posts: 22
Function to return an array of integer

Hi all,

I am trying to create a function that return an array of integer based on the char parameter pass into the function. I.e.

func_a(char * str)
{
example str is equal to "1,2,3,4"
return an array of integers of 1,2,3,4
}

Please advise

regards
dwgi32
Sponsored Links
  #2 (permalink)  
Old 11-19-2007
porter porter is offline Forum Advisor  
Registered User
 

Join Date: Jan 2007
Posts: 2,965
The C language does not let you return an array unless you either

(a) just return a pointer to the type of whatever the array is, and you have to allocate that array, eg you return an "int *".

(b) use a typedef to define the array, and then return that..



Code:
typedef int array_int3[4];

array_int3 func(...)
{
array_int3 ret={1,2,3,4};

     return ret;
}

  #3 (permalink)  
Old 11-20-2007
Registered User
 

Join Date: Nov 2007
Posts: 22
Hi Potter,

Tks a lot.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need to return value from function darshakraut Shell Programming and Scripting 5 05-14-2008 09:13 AM
function return array dophine Shell Programming and Scripting 6 05-06-2008 01:16 PM
Return an array of strings from user defined function in awk user_prady Shell Programming and Scripting 2 12-04-2007 12:03 AM
To return the elements of array Sudhakar333 Shell Programming and Scripting 5 08-06-2007 03:20 PM
C function to test string or integer qqq Programming 3 03-10-2005 01:55 AM



All times are GMT -4. The time now is 07:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0