I am new in learning c language and I am trying to learn about functions with char arrays. In this code I want to wrtie a function which uses a char array as a parameter and give another char array as a result. When I run the code the output should be : Helloooo world!
However, when I run the code the program crashes. How can I fix the problem? Am I using the right type of variables?
#include <stdio.h>
#include <string.h>
char *write();
int main()
{
char x[10] = "ooo";
printf("%s, world!\n", *write(x));
return 0;
}
char *write(char x[10])
{
char str[10];
strcpy(str, "Hello");
strcat(str,x);
x = str;
return x;
}