Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

a function which returns an array (or a string) how?

Posted on 1999-07-25
10
Medium Priority
?
186 Views
Last Modified: 2010-04-15
i don't know  how to make a function which returns an array.
i want to make a function which is taking as parameter a string and returns the same string.
how do i do that?
if i cant get the string parameter, so make the function return always the string "hello".


thanks
0
Comment
Question by:anonym
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 1263879
I'm not quite sure if I understand your Q right, but

char* ReturnString (char* string)
{
  if ( NULL == string) return ( "hello");

 return ( string);
}

should do it...

As 'string'  points to an existing string, you can safely return it...

Feel free to ask if you need more information!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1263880
jkr, congatulations for being one of the top 10 experts :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 1263881
Thanx Viktor, but you aren't too far beyond either ;-)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:viktornet
ID: 1263882
It'd take me a while 'till I get there.. been quite busy lately ;))
0
 

Author Comment

by:anonym
ID: 1263883
if i want to return a regular array (int array) and  not a char array

is it possible?
0
 
LVL 86

Expert Comment

by:jkr
ID: 1263884
Ooops - that's basically the same, just change

char* ReturnString (char* string)
{
  if ( NULL == string) return ( "hello");

 return ( string);
}

to read

int* ReturnArray (int* array, int size)
{
  if ( NULL == array || 0 == size)
    {
     printf ( "hello");

    return ( NULL);

 return ( array);
}
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1263885
opps, jkr has missed a single bracket :)

int* ReturnArray (int* array, int size)
     {
       if ( NULL == array || 0 == size)
         {
          printf ( "hello");

         return ( NULL);
        }   //THIS ONE I MEAN :)

      return ( array);
     }

Cheers,
Viktor
0
 
LVL 86

Expert Comment

by:jkr
ID: 1263886
Thanx Viktor - f&%$ copy&paste ;-)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1263887
:)
0
 

Author Comment

by:anonym
ID: 1263888
Thanks to you both!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question