zjm1126 zjm1126 - 4 years ago 83
C Question

How to return a string in my C code?

I am a C beginner and this is my C code:

#include <stdio.h>
#include <stdlib.h>
printf("Hello world !\n");
return 'sss';

that will show an error,

so how to return a string in C code?

Answer Source

If you are looking to return a string from a function(other than main), you should do something like this.

#include <stdio.h>
const char * getString();
int main()
 printf("hello world\n");
 printf("%s\n", getString());
 return 0;

const char * getString()
 const char *x = "abcstring";
 return x;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download