Results 1 to 4 of 4

Thread: Return string from a function in C

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

  2. #2
    Join Date
    Apr 2008
    Posts
    2,010

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

  3. #3
    Join Date
    May 2008
    Posts
    2,015

    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,302

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

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, 06: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, 08:45 PM
  4. How to return an array from function
    By Rilex in forum Software Development
    Replies: 3
    Last Post: 02-10-2009, 09:18 AM
  5. How to return a recordset from a function in ASP
    By Ananias in forum Software Development
    Replies: 3
    Last Post: 19-06-2009, 11:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •