Question: So, I'm trying to code a strcat function using pointers, just for studying purposes.

```
#include <stdio.h>
#include <string.h>

char *strcpyy(char *dest, char *orig){
    char *tmp = dest;
    while (*dest++ = *orig++);
    return tmp;
}

char *strcatt(char *dest, char *orig){
    strcpyy(dest + strlen(dest), orig);
    return dest;
}

int main(){
    char *a = "one";
    char *b = "two";
    printf("%s", strcatt(a,b));
}

```

When I run this code, the output is empty. Can anyone point out the problem?

Answer: 
[String literals](https://en.cppreference.com/w/c/language/string_literal) are read-only. Any attempt to write to a string literal will invoke [undefined behavior](https://en.wikipedia.org/wiki/Undefined_behavior), which means that your program may crash or not behave as intended.

Therefore, you should not use a pointer to a string literal as the first argument to `strcat` or your equivalent function. Instead, you must provide a pointer to an object which is writable and has sufficient space for the result (including the terminating null character), for example a `char` array of length `7`. This array can be initialized using a string literal.

Therefore, I recommend that you change the line

```
char *a = "one";

```

to the following:

```
char a[7] = "one";

```

After making this change, your program should work as intended.
You declared two pointers to string literals

```
char *a = "one";
char *b = "two";

```

You may not append one string literal to another.

Instead you need to define the variable `a` as a character array large enough to contain the appended string literal pointed to by the pointer `b`.

And the both functions should be declared like

```
char *strcpyy(char *dest, const char *orig);

char *strcatt(char *dest, const char *orig);

```

Also as you are using standard C string functions like `strlen`

```
strcpyy(dest + strlen(dest), orig);

```

then it will be logically consistent to use standard C function `strcpy` instead of your own function `strcpyy`.

Otherwise without using standard string functions your function `strcatt` can look the following way

```
char * strcatt( char *s1, const char *s2 )
{
    char *p = s1;

    while ( *p ) ++p;
    while ( ( *p++ = *s2++ ) != '\0' );

    return s1;
}

```

Here is a demonstration program.

```
#include <stdio.h>

char * strcatt( char *s1, const char *s2 )
{
    char *p = s1;

    while ( *p ) ++p;
    while ( ( *p++ = *s2++ ) != '\0' );

    return s1;
}

int main( void ) 
{
    char a[7] = "one";
    const char *b = "two";

    puts( strcatt( a, b ) );
}

```

The program output is

```
onetwo

```