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

Sponsored Links



Return string from a function in C

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-12-2009
Member
 
Join Date: Aug 2006
Posts: 162
Return string from a function in C
  

I am a beginner in C and I want to know how declare function which returns a string. I have tried to create but normally it gives me a segmentation stack run time error. Thank you to those who would explain to me ..

Reply With Quote
  #2  
Old 28-12-2009
Member
 
Join Date: Apr 2008
Posts: 2,000
Re: Return string from a function in C

Code:
 # include <stdio.h>

 char * function () (
	 char * str = "test";
	 return str;
 )

 int main () (
	 printf ( "% s \ n", function ());
	 return 0;
 )
Reply With Quote
  #3  
Old 28-12-2009
Member
 
Join Date: May 2008
Posts: 2,007
Re: Return string from a function in C

In the C API, certain functions return a string as a parameter. Each of these functions uses the same interface for retrieving a string. msStringProperty() is a pointer to a buffer provided by the application into which XMS copies the characters in the string.
Reply With Quote
  #4  
Old 28-12-2009
Member
 
Join Date: May 2008
Posts: 2,290
Re: Return string from a function in C

To return string from a function try this program :
ex:
Code:
#include 

char * cfun(void);
main ()
{
printf("%s\n",cfun());
}

char * cfun(void)
{
char *name;
name = (char *)malloc(20*sizeof(char));
printf("Enter name\n");
scanf("%s",nme);
return(nme);
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Return string from a function in C"
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 06:51 PM
How can I return different class in one function? Madaleno Software Development 4 10-02-2010 08:45 PM
How to return an array from function Rilex Software Development 3 02-10-2009 09:18 AM
How to return a recordset from a function in ASP Ananias Software Development 3 19-06-2009 11:35 PM


All times are GMT +5.5. The time now is 03:49 AM.